time format golang

Time Format

GoDoc License Release

a simple plugin to change date and time format

Features

  • parsing datetime to format global

Installing

go mod:

go get github.com/ibnusurkati/timeformat

Example

package main

import (
	"fmt"

	"github.com/ibnusurkati/timeformat"
)

func main() {
	// Get date  now
	DateNow()
	// Get date time now
	DateTimeNow()

	fmt.Println("===============================")

	// Parse date time
	ParseDateTime()

}

func DateNow() {
	date := timeformat.Now("YYYY-MM-DD")
	fmt.Println("DATE :", date)
}

func DateTimeNow() {
	datetime := timeformat.Now("YYYY-MM-DD hh:mm:ss")
	fmt.Println("DATETIME :", datetime)
}

func ParseDateTime() {
	datetime, err := timeformat.Parse("2021-09-13", "YYYY-MM-DD", "DD MMMM YYYY")

	if err != nil {
		fmt.Println("ERROR :", err)
		return
	}
	fmt.Println("DATETIME :", datetime)
}

Format Time

Format Format Go-Language Description
hh 15 24-hour format of an hour with leading zeros
h 3 12-hour format of an hour without leading zeros
mm 04 Minutes with leading zeros
m 4 Minutes without leading zeros
sss 05 Seconds with milliseconds
ss 05 Seconds with leading zeros
s 5 without with leading zeros
A PM Uppercase Ante meridiem and Post meridiem
a pm Lowercase Ante meridiem and Post meridiem

Format Date

Format Format Go-Language Description
YYYY 2006 A full numeric representation of a year, 4 digits
YY 06 A two digit representation of a year
MMMM January A full textual representation of a month, such as January or March
MMM Jan A short textual representation of a month, three letters
MM 01 Numeric representation of a month, with leading zeros
M 1 Numeric representation of a month, without leading zeros
DDDD Monday A full textual representation of the day of the week
DDD Mon A textual representation of a day, three letters
DD 02 Day of the month, 2 digits with leading zeros
D 2 Day of the month without leading zeros
Owner
Ibnu Surkati
Software Engineer
Ibnu Surkati
Similar Resources

🌐 A time zone helper

🌐 A time zone helper

🌐 A time zone helper tz helps you schedule things across time zones. It is an interactive TUI program that displays time across a few time zones of y

Dec 29, 2022

Clock is a small library for mocking time in Go.

clock Clock is a small library for mocking time in Go. It provides an interface around the standard library's time package so that the application can

Dec 30, 2022

A natural language date/time parser with pluggable rules

when when is a natural language date/time parser with pluggable rules and merge strategies Examples tonight at 11:10 pm at Friday afternoon the deadli

Dec 26, 2022

Copy of stdlib's time.Duration, but ParseDuration accepts other bigger units such as days, weeks, months and years

duration Copy of stdlib's time.Duration, but ParseDuration accepts other units as well: d: days (7 * 24 * time.Hour) w: weeks (7 * Day) mo: months (30

Jun 21, 2022

Structural time package for jalali calendar

Jalali Structural time package for jalali calendar. This package support parse from string, json and time. Structures There are three data structures

Mar 21, 2022

Timediff is a Go package for printing human readable, relative time differences 🕰️

timediff is a Go package for printing human readable, relative time differences. Output is based on ranges defined in the Day.js JavaScript library, and can be customized if needed.

Dec 25, 2022

Show time by timezone

Show time by timezone

Jan 22, 2022

Convert string to duration in golang

Go String To Duration (go-str2duration) This package allows to get a time.Duration from a string. The string can be a string retorned for time.Duratio

Dec 7, 2022

A simple, semantic and developer-friendly golang package for datetime

Carbon 中文 | English carbon 是一个轻量级、语义化、对开发者友好的 Golang 时间处理库,支持链式调用和 gorm、xorm、zorm 等主流 orm。 如果您觉得不错,请给个 star 吧 github:github.com/golang-module/carbon g

Jan 9, 2023
GoLang Parse many date strings without knowing format in advance.

Go Date Parser Parse many date strings without knowing format in advance. Uses a scanner to read bytes and use a state machine to find format. Much fa

Dec 31, 2022
Carbon for Golang, an extension for Time

Carbon A simple extension for Time based on PHP's Carbon library. Features: Time is embedded into Carbon (provides access to all of Time's functionali

Dec 20, 2022
:clock1: Date and Time - Golang Formatting Library
:clock1: Date and Time - Golang Formatting Library

Kair Date and Time - Golang Formatting Library Setup To get Kair > Go CLI go get github.com/GuilhermeCaruso/kair > Go DEP dep ensure -add github.com/G

Sep 26, 2022
Now is a time toolkit for golang

Now Now is a time toolkit for golang Install go get -u github.com/jinzhu/now Usage Calculating time based on current time import "github.com/jinzhu/n

Dec 23, 2022
Golang package to manipulate time intervals.

timespan timespan is a Go library for interacting with intervals of time, defined as a start time and a duration. Documentation API Installation Insta

Sep 26, 2022
timeutil - useful extensions (Timedelta, Strftime, ...) to the golang's time package

timeutil - useful extensions to the golang's time package timeutil provides useful extensions (Timedelta, Strftime, ...) to the golang's time package.

Dec 22, 2022
Go-timeparser - Flexible Time Parser for Golang

go-timeparser Flexible Time Parser for Golang Installation Download timeparser w

Dec 29, 2022
:clock8: Better time duration formatting in Go!

durafmt durafmt is a tiny Go library that formats time.Duration strings (and types) into a human readable format. go get github.com/hako/durafmt Why

Dec 16, 2022
Go time library inspired by Moment.js

Goment Current Version: 1.4.0 Changelog Goment is a port of the popular Javascript datetime library Moment.js. It follows the Moment.js API closely, w

Dec 24, 2022
fasttime - fast time formatting for go

fasttime - fast time formatting for go

Dec 13, 2022