1. Which package is primarily used for date and time in Go?
Answer:
Explanation:
The 'time' package in Go provides functionality for measuring and displaying time.
2. How do you get the current time in Go?
Answer:
Explanation:
The 'time.Now()' function is used to get the current local time in Go.
3. What is the return type of time.Now() in Go?
Answer:
Explanation:
The 'time.Now()' function returns a 'Time' struct representing the current local time.
4. How do you format a date in Go?
Answer:
Explanation:
In Go, the 'Format' method of the 'Time' type is used to format a date. The layout string "2006-01-02" is a reference time used to specify the format.
5. How do you parse a string into a time object in Go?
Answer:
Explanation:
The 'time.Parse' function is used to parse a string representation of time into a 'Time' object in Go.
6. How do you add a duration to a time in Go?
Answer:
Explanation:
The 'Add' method of the 'Time' type in Go is used to add a duration to a time.
7. How do you find the difference between two times in Go?
Answer:
Explanation:
The 'Sub' method in Go is used to find the duration between two 'Time' objects.
8. What is a 'Duration' in Go?
Answer:
Explanation:
A 'Duration' in Go represents a length of time as an int64 nanosecond count.
9. How do you get the current Unix timestamp in Go?
Answer:
Explanation:
The 'Unix' method of the 'Time' object in Go returns the Unix timestamp, the number of seconds elapsed since January 1, 1970 UTC.
10. How do you create a time object with a specific date in Go?
Answer:
Explanation:
The 'time.Date' function in Go is used to create a new 'Time' object with a specific date and time.
11. How do you find the day of the week for a given date in Go?
Answer:
Explanation:
The 'Weekday' method of a 'Time' object in Go returns the day of the week for that date.
12. What type is used to represent a time zone in Go?
Answer:
Explanation:
The 'Location' type in Go represents a geographical location and time zone.
13. How do you convert a time to a different time zone in Go?
Answer:
Explanation:
The 'In' method of a 'Time' object in Go is used to convert a time to the specified location's time zone.
14. What is the purpose of the 'After' function in the 'time' package in Go?
Answer:
Explanation:
The 'After' function in the 'time' package in Go is used to check if one time is after another.
15. How do you create a timer that fires once after a specified duration in Go?
Answer:
Explanation:
The 'NewTimer' function in Go returns a new 'Timer' that will send the current time on its channel after at least the duration has elapsed.