Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update hour, min, sec in golang time?

Tags:

time

go

Ex: How can I update hour in t time?

fmt.Println(t)
//=> 2006-01-02 15:04:05 +0000 UTC

Expect to get: 2006-01-02 00:00:00 +0000 UTC

Edited: similar to: time.Time Round to Day

like image 598
sreang rathanak Avatar asked Nov 24 '18 09:11

sreang rathanak


People also ask

How do I add time duration in Golang?

Add() function in Go language is used to add the stated time and duration. Moreover, this function is defined under the time package. Here, you need to import the “time” package in order to use these functions. Here, “t” is the stated time and “d” is the duration that is to be added to the time stated.

What is time second in Golang?

Return Value: It returns the second offset within the minute as provided by “t”. Example 1: // Golang program to illustrate the usage of. // Time.Second() function. // Including main package.

What does time duration do in Golang?

Duration has a base type int64. Duration represents the elapsed time between two instants as an int64 nanosecond count”. The maximum possible nanosecond representation is up to 290 years.

Which is valid go time format literal?

Golang Time Format YYYY-MM-DD.


1 Answers

Use:

t1 := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, t.Nanosecond(), t.Location())

Ref: https://golang.org/pkg/time/#Date

like image 53
Shudipta Sharma Avatar answered Sep 21 '22 12:09

Shudipta Sharma