Golang Data time toolkit


Now is a very simple package that provides a convenience wrapper for the standard time package and makes it easy to work with various date and time constructs around the current time.

Installation
go get -u github.com/jinzhu/now

Example

package main

import (
	"fmt"
	"time"

	"github.com/jinzhu/now"
)

func main() {
	fmt.Println("BeginningOfMinute \t", now.BeginningOfMinute())
	fmt.Println("BeginningOfHour \t", now.BeginningOfHour())
	fmt.Println("BeginningOfDay  \t", now.BeginningOfDay())
	fmt.Println("BeginningOfWeek \t", now.BeginningOfWeek())
	fmt.Println("BeginningOfMonth \t", now.BeginningOfMonth())
	fmt.Println("BeginningOfQuarter \t", now.BeginningOfQuarter())
	fmt.Println("BeginningOfYear \t", now.BeginningOfYear())
	fmt.Println()

	fmt.Println("EndOfMinute \t", now.EndOfMinute())
	fmt.Println("EndOfHour \t", now.EndOfHour())
	fmt.Println("EndOfDay  \t", now.EndOfDay())
	fmt.Println("EndOfWeek \t", now.EndOfWeek())
	fmt.Println("EndOfMonth \t", now.EndOfMonth())
	fmt.Println("EndOfQuarter \t", now.EndOfQuarter())
	fmt.Println("EndOfYear \t", now.EndOfYear())
	fmt.Println()

	fmt.Println("Monday 	\t", now.Monday())
	fmt.Println("Sunday 	\t", now.Sunday())
	fmt.Println("EndOfSunday \t", now.EndOfSunday())
	fmt.Println()

	fmt.Println(now.Parse("2017"))
	fmt.Println(now.Parse("2017-12-12 12:20"))

	t := time.Date(2020, 07, 18, 17, 51, 49, 123456789, time.Now().Location())
	fmt.Println(now.With(t).EndOfMonth())
}

Output

BeginningOfMinute        2020-07-19 16:55:00 +0530 IST
BeginningOfHour          2020-07-19 16:00:00 +0530 IST
BeginningOfDay           2020-07-19 00:00:00 +0530 IST
BeginningOfWeek          2020-07-19 00:00:00 +0530 IST
BeginningOfMonth         2020-07-01 00:00:00 +0530 IST
BeginningOfQuarter       2020-07-01 00:00:00 +0530 IST
BeginningOfYear          2020-01-01 00:00:00 +0530 IST

EndOfMinute      2020-07-19 16:55:59.999999999 +0530 IST
EndOfHour        2020-07-19 16:59:59.999999999 +0530 IST
EndOfDay         2020-07-19 23:59:59.999999999 +0530 IST
EndOfWeek        2020-07-25 23:59:59.999999999 +0530 IST
EndOfMonth       2020-07-31 23:59:59.999999999 +0530 IST
EndOfQuarter     2020-09-30 23:59:59.999999999 +0530 IST
EndOfYear        2020-12-31 23:59:59.999999999 +0530 IST

Monday           2020-07-13 00:00:00 +0530 IST
Sunday           2020-07-19 00:00:00 +0530 IST
EndOfSunday      2020-07-19 23:59:59.999999999 +0530 IST

2017-01-01 00:00:00 +0530 IST 
2017-12-12 12:20:00 +0530 IST 
2020-07-31 23:59:59.999999999 +0530 IST
Most Helpful This Week