for what
- this project used to golang timezone
depends
in go mod project
$ git ls-remote -q http://github.com/sinlovgo/timezone.git
$ go list -v -m -versions github.com/sinlovgo/timezone
$ echo "go mod edit -require=$(go list -m -versions github.com/sinlovgo/timezone | awk '{print $1 "@" $NF}')"
$ echo "go mod vendor"
usage
set timezone
import "github.com/sinlovgo/timezone"
func main() {
timezone.Second()
timezone.Micro()
timezone.TimestampSecond()
timezone.TimestampUnixNano()
timezone.UTCSecond()
timezone.UTCMicro()
timezone.SetZoneByName(timezone.ZoneAsiaShanghai)
timezone.ZoneUTC
timezone.ZoneGMT
timezone.ZoneCET
timezone.ZoneCST
timezone.SetZoneLocation()
timezone.ZoneCEST
}
layout
format for golang
import "github.com/sinlovgo/timezone"
timezone.LayoutSecond
timezone.LayoutMicro
timezone.LayoutISO8601TimeSecond
timezone.LayoutISO8601TimeMicro
timezone.LayoutISO8601TimeUTC
now
import "github.com/sinlovgo/timezone"
func main() {
timezone.Second()
timezone.Micro()
timezone.TimestampSecond()
timezone.TimestampUnixNano()
timezone.UTCSecond()
timezone.UTCMicro()
timezone.SetZoneByName(timezone.ZoneAsiaShanghai)
timezone.SetZoneLocation()
}
Parse
import "github.com/sinlovgo/timezone"
func main() {
timestamp, err := timezone.ParseTimestamp("2006-01-02 15:04:05", "2018-07-11 15:07:51")
timestampSecond, err := timestamp.ParseTimestampSecond("2018-07-11 15:07:51")
}
timeparse
import "github.com/sinlovgo/timezone/timeparse"
func main() {
testTime := "2020-02-25T16:52:18Z"
parseLocation, err := Location(timezone.LayoutISO8601TimeSecond, timezone.LayoutISO8601TimeMicro,
testTime,
timezone.ZoneUTC, timezone.ZoneAsiaShanghai)
}
Compare
import "github.com/sinlovgo/timezone"
func main() {
timeFrom := "2018-07-11 15:07:51"
timeTo := "2018-07-12 15:07:51"
compareLocationEQ, err := timestamp.CompareEQ(timeFrom, timeTo, "2006-01-02 15:04:05")
timeFrom := "2018-07-11 15:07:51"
timeTo := "2018-07-12 15:07:51"
compareLocation, err := timestamp.CompareGT(timeFrom, timeTo, timestamp.LayoutSecond)
timeFrom := "2018-07-11 15:07:51"
timeTo := "2018-07-12 15:07:51"
compare, err := timestamp.CompareSecondLT(timeFrom, timeTo)
}
Calc
import "github.com/sinlovgo/timezone"
func main() {
calcDurationSecond := time.Duration(-30) * time.Minute
calcDuration := timestamp.CalcDuration(calcDurationSecond, timestamp.LayoutMicro)
calcDateSecond := timestamp.CalcDateSecond(2, 3, 10)
calcDateMicro := timestamp.CalcDateMicro(2, 2, 2)
calcDay := timestamp.CalcDay(10, LayoutSecond)
calcDaySecond := timestamp.CalcDaySecond(1)
calcMonthSecond := timestamp.CalcMonthSecond(-1)
calcYearSecond := timestamp.CalcYearSecond(-1)
}
start time
import "github.com/sinlovgo/timezone"
func main() {
yesterdaySecond := StartDaySecond(-1)
lastMonthMicro := StartMonthMicro(-1)
lastYearSecond := StartYearSecond(-1)
}
dev
make init
make test
add main.go file and run
make run
dev
evn
docker
base docker file can replace