This is a creation in Article, where the information may have evolved or changed.
Package Mainimport "FMT" import "Time" Func main () {p: = fmt. PRINTLN//We ll start by getting the current time. Now: = time. Now () p ("time. Now (): ' Now '//You can build a ' time ' struct by providing the//year, month, day, etc. Times is always associated//with a ' location ', i.e. time zone. Then: = time. Date (one, one, a, a, a, 651387237, time). UTC) P ("time. Date (): ", then) p (" ================================== ")//can extract the various components of the time// Value as expected. P ("time. Date (). Year (): "and then." Year ()) p ("time. Date (). Month (): ", then. Month ()) p ("time. Date (). Day (): "and then." Day ()) p ("time. Date (). Hour (): ", then. Hour ()) p ("time. Date (). Minute (): ", then. Minute ()) p ("time. Date (). Second (): ", then. Second ()) p ("time. Date (). Nanosecond (): ", then. Nanosecond ()) p ("time. Date (). Location (): "and then. Location ())//The Monday-sunday ' Weekday ' is also available. P ("time. Date (). Weekday (): ", then. Weekday ()) p ("==================================")//These methods compare the times, testing if the//first occurs BEFO Re, after, or at the same time//as the second, respectively. P ("time. Date (). Before (now): "and then." Before (now)) p ("time. Date (). After (now): "and then. After (now) p ("Time"). Date (). Equal (now): "and then." Equal (now)) p ("==================================")//The "Sub" Methods returns a "Duration" representing//the Interval between. diff: = now. Sub (then) p ("time. Now (). Sub (time. Date ()): ", diff) p (" ================================== ")//We can compute the length of the duration in//Vari ous units. P ("time. Date (). Sub (then). Hours (): ", diff. Hours ()) p ("time. Date (). Sub (then). Minutes (): ", diff. Minutes ()) p ("time. Date (). Sub (then). Seconds (): ", diff. Seconds ()) p ("time. Date (). Sub (then). nanoseconds (): ", diff. nanoseconds ()) p ("==================================")//can use ' Add ' to advance a time by a given// Duration, or with a "-" to move backwards by a//duration. P ("time. Date (). Sub (now). ADD (now. Sub): ", now. Add (diff)) p ("time. Date (). Sub (then). ADD (-(now). SUB)): ", then. ADD (-diff))}