Working with Different Time Zones

Let’s learn how to work with different time zones.

We'll cover the following

The presented utility accepts a date and a time and converts them into different time zones. This can be particularly handy when we want to preprocess log files from different sources that use different time zones in order to convert these different time zones into a common one.

Once again, we need time.Parse() in order to convert a valid input into a time.Time value before doing the conversions. This time, the input string contains the time zone and is parsed by the "02 January 2006 15:04 MST" string.

Coding example

In order to convert the parsed date and time into New York time, the program uses the following code:

Get hands-on with 1200+ tech skills courses.