{"id":810,"date":"2026-10-08T13:00:00","date_gmt":"2026-10-08T07:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/"},"modified":"2026-11-29T01:29:31","modified_gmt":"2026-11-28T19:59:31","slug":"go-date-time-programs","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/","title":{"rendered":"Go Date and Time Programs: Format, Parse, Age and Time Zones"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go date and time programs work with dates, clocks and durations, such as showing an order date, finding someone&#8217;s age or counting days until a deadline. Go&#8217;s <code>time<\/code> package handles all of this, but it has one unusual rule: you format dates with a fixed example date instead of codes like <code>YYYY<\/code>. In this post, you will write fourteen date and time programs with their exact output, and then practice the time questions that interviewers like to ask.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We already used <code>time<\/code> briefly in our <a href=\"https:\/\/smitabharat.com\/blog\/go-function-programs\/\">Go function programs<\/a>. For the full package tour, read the <a href=\"https:\/\/smitabharat.com\/blog\/go-time-package-examples\/\">Go time package guide with examples<\/a>. Every program here uses fixed dates, so the output stays the same in the Go Playground and on your machine. All programs were tested on Go 1.27.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Go Date and Time Programs?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go date and time programs use the <code>time.Time<\/code> type for a moment in time and <code>time.Duration<\/code> for a length of time. A <code>Time<\/code> holds the date, the clock time and a location, such as UTC or India Standard Time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of <code>time.Time<\/code> as a stamp on a parcel that says exactly when it was posted and in which city. A <code>time.Duration<\/code> is the gap between two stamps, like &#8220;3 days and 4 hours&#8221;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Date and Time Programs Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Almost every app shows or stores time, so Go date and time programs are worth practising. For example, a shop prints invoice dates, a bank calculates interest days, a gym app tracks workout length and a server logs when each request arrived. Mistakes here cause real bugs, such as wrong ages or deadlines that are off by a day.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Display:<\/strong> show dates in the format users expect, like 15-08-2026.<\/li>\n\n\n<li><strong>Maths:<\/strong> add days, find differences and work out ages.<\/li>\n\n\n<li><strong>Time zones:<\/strong> store in UTC and show local time to each user.<\/li>\n\n\n<li><strong>Interviews:<\/strong> the layout date, durations and time zone questions are common.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Date and Time Programs Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go formats and parses dates using a reference time: <strong>Mon Jan 2 15:04:05 MST 2006<\/strong>. Each part has a number that is easy to remember in order: month 1, day 2, hour 3 (15), minute 4, second 5, year 6, zone 7 (MST is -0700). You write a layout that looks like that date, and Go swaps in your real values.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-1-1024x640.png\" alt=\"Go date and time programs diagram showing the reference layout Mon Jan 2 15:04:05 2006 and each part\" class=\"wp-image-783\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Go uses the reference time 2006-01-02 15:04:05, so every layout is written as that date in the shape you want.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The table below shows the layout parts you will use most.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>You want<\/th><th>Layout part<\/th><th>Example output<\/th><\/tr><\/thead><tbody><tr><td>Year<\/td><td>2006<\/td><td>2026<\/td><\/tr><tr><td>Month number<\/td><td>01<\/td><td>08<\/td><\/tr><tr><td>Month name<\/td><td>Jan or January<\/td><td>Aug or August<\/td><\/tr><tr><td>Day<\/td><td>02<\/td><td>15<\/td><\/tr><tr><td>Weekday<\/td><td>Mon or Monday<\/td><td>Sat or Saturday<\/td><\/tr><tr><td>24-hour clock<\/td><td>15:04<\/td><td>18:30<\/td><\/tr><tr><td>12-hour clock<\/td><td>3:04 PM<\/td><td>6:30 PM<\/td><\/tr><tr><td>Seconds<\/td><td>05<\/td><td>09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Go Date and Time Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These first Go date and time programs create and format dates. If you are new to Go, start with Program 1. It is the smallest date program you can write.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 1: Your First Date Program<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"  \/\/ fmt prints text on the screen\n    \"time\" \/\/ time works with dates, clocks and durations\n)\n\nfunc main() {\n    \/\/ time.Date builds a date: year, month, day, hour, minute, second, nanosecond, zone.\n    \/\/ := creates a new variable and stores the value in it.\n    independenceDay := time.Date(2026, time.August, 15, 0, 0, 0, 0, time.UTC)\n\n    \/\/ Format turns the date into text. \"02-01-2006\" means day-month-year.\n    fmt.Println(\"Date:\", independenceDay.Format(\"02-01-2006\"))\n\n    \/\/ Weekday tells you the day of the week for this date.\n    fmt.Println(\"Day of week:\", independenceDay.Weekday())\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Date: 15-08-2026\nDay of week: Saturday<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, <code>time.Date<\/code> builds a fixed date and stores it in <code>independenceDay<\/code>. Then <code>Format<\/code> prints it in the day-month-year style. Finally, <code>Weekday<\/code> looks up the day name for you.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 2: Create a Date and Read Its Parts<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    \/\/ Build 15 August 2026 at 18:30 in UTC.\n    moment := time.Date(2026, time.August, 15, 18, 30, 0, 0, time.UTC)\n\n    \/\/ Printing a time directly shows the date, the clock time and the zone.\n    fmt.Println(moment)\n\n    \/\/ Each method reads one part of the date.\n    fmt.Println(moment.Year(), moment.Month(), moment.Day())\n    fmt.Println(moment.Weekday(), moment.YearDay()) \/\/ YearDay is the day number in the year\n    fmt.Println(moment.Hour(), moment.Minute())\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>2026-08-15 18:30:00 +0000 UTC\n2026 August 15\nSaturday 227\n18 30<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>time.Date<\/code> builds any moment you need. After that, small methods like <code>Year<\/code>, <code>Month<\/code> and <code>Hour<\/code> read one part each. <code>YearDay<\/code> gives the day number in the year, which is 227 here.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 3: Format a Date Many Ways<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    moment := time.Date(2026, time.August, 15, 18, 30, 9, 0, time.UTC)\n\n    \/\/ Each layout is the reference date written in the shape you want.\n    fmt.Println(moment.Format(\"02-01-2006\"))             \/\/ day-month-year\n    fmt.Println(moment.Format(\"2006\/01\/02 15:04:05\"))    \/\/ year first, 24-hour clock\n    fmt.Println(moment.Format(\"Monday, 2 January 2006\")) \/\/ full weekday and month names\n    fmt.Println(moment.Format(\"Jan 2, 2006 at 3:04 PM\")) \/\/ 12-hour clock with PM\n    fmt.Println(moment.Format(time.RFC3339))             \/\/ standard format for APIs\n\n    \/\/ time.DateOnly and time.TimeOnly are ready-made layouts.\n    fmt.Println(moment.Format(time.DateOnly), moment.Format(time.TimeOnly))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>15-08-2026\n2026\/08\/15 18:30:09\nSaturday, 15 August 2026\nAug 15, 2026 at 6:30 PM\n2026-08-15T18:30:09Z\n2026-08-15 18:30:09<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You pass a layout string to <code>Format<\/code>, and Go fills in the real values. So <code>02-01-2006<\/code> gives the Indian style day-month-year. <code>time.RFC3339<\/code> is the standard for APIs and JSON. <code>time.DateOnly<\/code> and <code>time.TimeOnly<\/code> are handy constants added in Go 1.20.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 4: Check If a Date Is a Weekend<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\n\/\/ isWeekend returns true when the date is a Saturday or a Sunday.\nfunc isWeekend(date time.Time) bool {\n    day := date.Weekday()\n    if day == time.Saturday || day == time.Sunday { \/\/ || means \"or\"\n        return true\n    }\n    return false\n}\n\nfunc main() {\n    \/\/ A slice is a list. Here it holds three dates.\n    dates := []time.Time{\n        time.Date(2026, time.October, 16, 0, 0, 0, 0, time.UTC),\n        time.Date(2026, time.October, 17, 0, 0, 0, 0, time.UTC),\n        time.Date(2026, time.October, 18, 0, 0, 0, 0, time.UTC),\n    }\n\n    \/\/ range gives you each date in the list. The _ skips the index we do not need.\n    for _, date := range dates {\n        fmt.Println(date.Format(\"02 Jan 2006\"), date.Weekday(), \"weekend:\", isWeekend(date))\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>16 Oct 2026 Friday weekend: false\n17 Oct 2026 Saturday weekend: true\n18 Oct 2026 Sunday weekend: true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>isWeekend<\/code> function reads the weekday and compares it with <code>time.Saturday<\/code> and <code>time.Sunday<\/code>. Then the loop checks each date in the list. A check like this is handy when you plan deliveries or office work days.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 5: Parse a String into a Time<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    \/\/ Parse reads text using a layout and returns a time.\n    \/\/ err is the error value. It is nil (empty) when everything worked.\n    meeting, err := time.Parse(\"02-01-2006 15:04\", \"26-01-2027 09:15\")\n    fmt.Println(meeting, err)\n\n    \/\/ 31 February does not exist, so Parse returns an error.\n    \/\/ The _ throws away the time value because we only want the error.\n    _, err = time.Parse(\"02-01-2006\", \"31-02-2027\")\n    fmt.Println(err)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>2027-01-26 09:15:00 +0000 UTC &lt;nil&gt;\nparsing time \"31-02-2027\": day out of range<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>time.Parse<\/code> takes the layout first and the text second. The layout must match the input shape exactly. Go also checks the date itself, so 31 February is rejected with a clear error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Date Maths in Go Date and Time Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go date and time programs add to dates and find gaps between them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 6: Add Days, Months and Hours<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    order := time.Date(2026, time.October, 5, 10, 0, 0, 0, time.UTC)\n\n    \/\/ AddDate takes years, months and days.\n    delivery := order.AddDate(0, 0, 7) \/\/ 7 days later\n    warranty := order.AddDate(1, 0, 0) \/\/ 1 year later\n\n    \/\/ Add takes a Duration, such as 36 hours.\n    reminder := order.Add(36 * time.Hour)\n\n    fmt.Println(\"Delivery:\", delivery.Format(\"02 Jan 2006\"))\n    fmt.Println(\"Warranty ends:\", warranty.Format(\"02 Jan 2006\"))\n    fmt.Println(\"Reminder:\", reminder.Format(\"02 Jan 2006 15:04\"))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Delivery: 12 Oct 2026\nWarranty ends: 05 Oct 2027\nReminder: 06 Oct 2026 22:00<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>AddDate(years, months, days)<\/code> works with calendar units. On the other hand, <code>Add<\/code> takes a <code>Duration<\/code>, such as 36 hours. Both return a new time, so the original order date stays the same.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 7: Days Between Two Dates<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    start := time.Date(2026, time.January, 1, 0, 0, 0, 0, time.UTC)\n    end := time.Date(2026, time.December, 25, 0, 0, 0, 0, time.UTC)\n\n    \/\/ Step 1: Sub gives the gap between two times as a Duration.\n    gap := end.Sub(start)\n    fmt.Println(gap)\n\n    \/\/ Step 2: turn the gap into hours, then divide by 24 to get days.\n    hours := gap.Hours()\n    days := int(hours \/ 24) \/\/ int() drops the decimal part\n    fmt.Println(\"Days:\", days)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>8592h0m0s\nDays: 358<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Sub<\/code> returns a <code>Duration<\/code>, which prints in hours. Next, <code>Hours<\/code> gives that gap as a number. Dividing it by 24 gives whole days.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 8: Age Calculator<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\n\/\/ age returns how many full years have passed from birth to today.\nfunc age(birth, today time.Time) int {\n    \/\/ Step 1: subtract the birth year from this year.\n    years := today.Year() - birth.Year()\n\n    \/\/ Step 2: if this year's birthday has not come yet, take one year away.\n    if today.YearDay() &lt; birth.YearDay() {\n        years--\n    }\n    return years\n}\n\nfunc main() {\n    birth := time.Date(1995, time.November, 20, 0, 0, 0, 0, time.UTC)\n    today := time.Date(2026, time.October, 18, 0, 0, 0, 0, time.UTC)\n    fmt.Println(\"Age:\", age(birth, today))\n\n    birthday := time.Date(2026, time.November, 20, 0, 0, 0, 0, time.UTC)\n    fmt.Println(\"Age on 20 Nov 2026:\", age(birth, birthday))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Age: 30\nAge on 20 Nov 2026: 31<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We subtract the years, then take one away if this year&#8217;s birthday has not come yet. In real code, pass <code>time.Now()<\/code> as <code>today<\/code>. Comparing <code>YearDay<\/code> can be one day off around 29 February in leap years. For that reason, production code often compares month and day instead.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 9: Last Day of a Month<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\n\/\/ lastDay returns the number of days in the given month.\nfunc lastDay(year int, month time.Month) int {\n    \/\/ Day 0 of next month means \"one day before the 1st\", which is the last day of this month.\n    dayBeforeNextMonth := time.Date(year, month+1, 0, 0, 0, 0, 0, time.UTC)\n    return dayBeforeNextMonth.Day()\n}\n\nfunc main() {\n    fmt.Println(lastDay(2026, time.February), lastDay(2028, time.February))\n    fmt.Println(lastDay(2026, time.April), lastDay(2026, time.December))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>28 29\n30 31<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>time.Date<\/code> fixes values that are out of range. So day 0 of March becomes the last day of February. As a bonus, this also handles leap years for free.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Durations in Go Date and Time Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go date and time programs measure and compare lengths of time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 10: Work with Durations<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    \/\/ A Duration is built from units like time.Hour and time.Minute.\n    workout := 1*time.Hour + 25*time.Minute + 30*time.Second\n    fmt.Println(workout)\n    fmt.Println(workout.Minutes())              \/\/ the whole duration in minutes\n    fmt.Printf(\"%.1f hours\\n\", workout.Hours()) \/\/ %.1f prints one decimal place\n\n    \/\/ ParseDuration reads a duration from text.\n    trip, err := time.ParseDuration(\"2h45m\")\n    fmt.Println(trip, err, trip &gt; workout) \/\/ durations can be compared with &gt; and &lt;\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1h25m30s\n85.5\n1.4 hours\n2h45m0s &lt;nil&gt; true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>Duration<\/code> is just a number of nanoseconds. So you can add, compare and print it like a number. <code>ParseDuration<\/code> reads strings like &#8220;90s&#8221; or &#8220;2h45m&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 11: Compare Two Times<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    deadline := time.Date(2026, 10, 20, 17, 0, 0, 0, time.UTC)\n    submitted := time.Date(2026, 10, 20, 16, 45, 0, 0, time.UTC)\n\n    fmt.Println(\"On time:\", submitted.Before(deadline)) \/\/ true if submitted is earlier\n    fmt.Println(\"Late:\", submitted.After(deadline))     \/\/ true if submitted is later\n    fmt.Println(\"Margin:\", deadline.Sub(submitted))     \/\/ how much time was left\n\n    \/\/ Compare gives -1 (earlier), 0 (same) or 1 (later).\n    fmt.Println(deadline.Compare(submitted))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>On time: true\nLate: false\nMargin: 15m0s\n1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Before<\/code> and <code>After<\/code> answer simple yes or no questions. <code>Compare<\/code> returns -1, 0 or 1, just like <code>cmp.Compare<\/code>. It was added in Go 1.20 and works well with <code>slices.SortFunc<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Time Zones in Go Date and Time Programs<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Program 12: Convert Between UTC and IST<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    \/\/ FixedZone makes a zone with a name and an offset in seconds.\n    \/\/ IST is 5 hours 30 minutes ahead of UTC.\n    ist := time.FixedZone(\"IST\", 5*3600+30*60)\n    meeting := time.Date(2026, 10, 20, 9, 30, 0, 0, time.UTC)\n\n    \/\/ In shows the same moment in another zone.\n    fmt.Println(\"UTC:\", meeting.Format(\"15:04 MST\"))\n    fmt.Println(\"IST:\", meeting.In(ist).Format(\"15:04 MST\"))\n\n    \/\/ A time made in IST can be turned back into UTC.\n    istMeeting := time.Date(2026, 10, 20, 9, 30, 0, 0, ist)\n    fmt.Println(istMeeting.UTC().Format(time.RFC3339))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>UTC: 09:30 UTC\nIST: 15:00 IST\n2026-10-20T04:00:00Z<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, <code>FixedZone<\/code> creates the IST zone. Then <code>In<\/code> shows the same moment in that zone, and <code>UTC<\/code> converts back. In real apps, use <code>time.LoadLocation(\"Asia\/Kolkata\")<\/code>, which also knows daylight saving rules.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 13: Unix Timestamps<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    newYear := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)\n\n    \/\/ Unix gives the number of seconds since 1 January 1970 UTC.\n    fmt.Println(newYear.Unix())\n\n    \/\/ time.Unix goes the other way: seconds back into a time.\n    fmt.Println(time.Unix(0, 0).UTC())\n    fmt.Println(time.Unix(1767225600, 0).UTC().Format(time.DateOnly))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1767225600\n1970-01-01 00:00:00 +0000 UTC\n2026-01-01<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A Unix timestamp counts seconds since 1 January 1970 UTC. <code>Unix<\/code> turns a time into that number, and <code>time.Unix<\/code> turns it back. Databases and APIs often store time this way.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 14: Truncate and Round to the Hour<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    eventTime := time.Date(2026, 10, 20, 14, 47, 31, 0, time.UTC)\n\n    fmt.Println(eventTime.Truncate(time.Hour).Format(time.TimeOnly))        \/\/ always rounds down\n    fmt.Println(eventTime.Round(time.Hour).Format(time.TimeOnly))           \/\/ goes to the nearest hour\n    fmt.Println(eventTime.Truncate(15 * time.Minute).Format(time.TimeOnly)) \/\/ down to a 15-minute step\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>14:00:00\n15:00:00\n14:45:00<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Truncate<\/code> always goes down, and <code>Round<\/code> goes to the nearest step. Here 14:47 is closer to 15:00, so <code>Round<\/code> moves it up. This is useful for grouping events into hourly or 15-minute slots.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">time.Time vs time.Duration in Go Date and Time Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In Go date and time programs, these two types are easy to mix up. The diagram and table below compare them.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-2-1024x640.png\" alt=\"Go date and time programs comparison of time.Time and time.Duration\" class=\"wp-image-784\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">time.Time is a point on the timeline, while time.Duration is the distance between two points.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>time.Time<\/th><th>time.Duration<\/th><\/tr><\/thead><tbody><tr><td>Means<\/td><td>A moment, like 20 Oct 2026 09:30<\/td><td>A length, like 90 minutes<\/td><\/tr><tr><td>Created with<\/td><td>time.Date, time.Now, time.Parse<\/td><td>time.Hour * 2, ParseDuration<\/td><\/tr><tr><td>Has a time zone<\/td><td>Yes<\/td><td>No<\/td><\/tr><tr><td>Add them together<\/td><td>Time + Duration with Add<\/td><td>Duration + Duration<\/td><\/tr><tr><td>Difference of two<\/td><td>t2.Sub(t1) gives a Duration<\/td><td>Simple subtraction<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So a <code>Time<\/code> answers &#8220;when&#8221;, and a <code>Duration<\/code> answers &#8220;how long&#8221;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in Go Date and Time Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Using YYYY-MM-DD:<\/strong> Go needs the reference date, so write <code>2006-01-02<\/code>.<\/li>\n\n\n<li><strong>Mixing up 01 and 02:<\/strong> <code>01<\/code> is the month and <code>02<\/code> is the day, so <code>02-01-2006<\/code> is day-month-year.<\/li>\n\n\n<li><strong>Comparing with ==:<\/strong> two equal moments in different zones are not <code>==<\/code>. Use <code>Equal<\/code>.<\/li>\n\n\n<li><strong>Storing local time:<\/strong> save times in UTC and convert to local only when you show them.<\/li>\n\n\n<li><strong>Assuming every day has 24 hours:<\/strong> in zones with daylight saving, use <code>AddDate<\/code> for calendar days.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Date and Time Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use time.RFC3339<\/strong> for APIs, JSON and logs.<\/li>\n\n\n<li><strong>Keep times in UTC<\/strong> in databases and convert at the edges.<\/li>\n\n\n<li><strong>Use constants like time.Hour<\/strong> instead of raw numbers of seconds.<\/li>\n\n\n<li><strong>Pass the current time into functions<\/strong> like <code>age(birth, now)<\/code>, so tests can use fixed dates.<\/li>\n\n\n<li><strong>Check parse errors<\/strong>, because user dates are often wrong.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Go Date and Time Programs Interview Questions and Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers use short Go date and time programs to test the special rules of the <code>time<\/code> package. Each program is complete, with real output from Go 1.27.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Format and Parse Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. Why does Go use 2006-01-02 15:04:05 for layouts?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is a reference time where each part is a different number in order: 1 (month), 2 (day), 3 (hour), 4 (minute), 5 (second), 6 (year) and -7 (zone). So you write the layout as an example of the output you want.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    moment := time.Date(2026, 3, 7, 5, 4, 9, 0, time.UTC)\n    fmt.Println(moment.Format(\"2-1-06 3:4:5\"))        \/\/ no leading zeros\n    fmt.Println(moment.Format(\"02-01-2006 03:04:05\")) \/\/ leading zeros\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>7-3-26 5:4:9\n07-03-2026 05:04:09<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Without leading zeros, <code>2<\/code>, <code>1<\/code>, <code>3<\/code>, <code>4<\/code> and <code>5<\/code> print single digits. Adding a <code>0<\/code> in front, as in <code>02<\/code>, pads them to two digits. Also, <code>06<\/code> gives a two-digit year.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    \/\/ The layout uses dashes, but the text uses slashes.\n    _, err := time.Parse(\"2006-01-02\", \"2026\/10\/20\")\n    fmt.Println(err)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>parsing time \"2026\/10\/20\" as \"2006-01-02\": cannot parse \"\/10\/20\" as \"-\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The layout uses dashes, but the input uses slashes. The error message shows exactly where the shapes stop matching.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Duration and Maths Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    januaryEnd := time.Date(2026, 1, 31, 0, 0, 0, 0, time.UTC)\n    fmt.Println(januaryEnd.AddDate(0, 1, 0).Format(time.DateOnly)) \/\/ add one month\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>2026-03-03<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Adding one month to 31 January gives &#8220;31 February&#8221;, which does not exist. Go normalises it to 3 March in 2026. Handle month ends with care in billing code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    lesson := 90 * time.Minute\n    leftoverMinutes := int(lesson.Minutes()) % 60 \/\/ % gives the remainder\n    fmt.Println(lesson, lesson.Hours(), leftoverMinutes)\n\n    \/\/ 1500 times one millisecond is 1.5 seconds.\n    fmt.Println(time.Duration(1500) * time.Millisecond)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1h30m0s 1.5 30\n1.5s<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ninety minutes prints as <code>1h30m0s<\/code>, and <code>Hours<\/code> gives 1.5. The remainder of 90 divided by 60 is 30 leftover minutes. Go also picks the neatest unit when it prints a duration, such as <code>1.5s<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6. What is the zero value of time.Time?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    var emptyTime time.Time \/\/ declared but never set\n    fmt.Println(emptyTime)\n    fmt.Println(emptyTime.IsZero())\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>0001-01-01 00:00:00 +0000 UTC\ntrue<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It is the start of year 1 in UTC. Use <code>IsZero<\/code> to check whether a time was never set.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Comparison and Zone Questions for Go Date and Time Programs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    ist := time.FixedZone(\"IST\", 19800) \/\/ 19800 seconds is 5 hours 30 minutes\n    utcTime := time.Date(2026, 10, 20, 4, 0, 0, 0, time.UTC)\n    istTime := time.Date(2026, 10, 20, 9, 30, 0, 0, ist)\n    fmt.Println(utcTime == istTime, utcTime.Equal(istTime))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>false true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Both values are the same moment, but they store different locations. <code>==<\/code> compares everything, while <code>Equal<\/code> compares only the moment. So always use <code>Equal<\/code> for times.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8. Why might time.LoadLocation fail?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It reads time zone data from the operating system. Small Docker images may not have that data, so the call returns an error. Import <code>time\/tzdata<\/code> to embed the data in your binary.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    date := time.Date(2026, 10, 18, 0, 0, 0, 0, time.UTC)\n    year, week := date.ISOWeek() \/\/ ISOWeek returns two values\n    fmt.Println(date.Weekday(), year, week)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Sunday 2026 42<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ISOWeek<\/code> gives the ISO 8601 week number, which many reports use. It returns the year and the week together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10. How do you measure how long code takes?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save <code>start := time.Now()<\/code> before the code, and call <code>time.Since(start)<\/code> after it. <code>time.Now<\/code> includes a monotonic clock reading, so the result stays correct even if the system clock changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"slices\"\n    \"time\"\n)\n\n\/\/ earlierFirst tells SortFunc how to order two dates.\nfunc earlierFirst(first, second time.Time) int {\n    return first.Compare(second)\n}\n\nfunc main() {\n    dates := []time.Time{\n        time.Date(2026, 12, 1, 0, 0, 0, 0, time.UTC),\n        time.Date(2026, 3, 15, 0, 0, 0, 0, time.UTC),\n        time.Date(2026, 7, 4, 0, 0, 0, 0, time.UTC),\n    }\n    slices.SortFunc(dates, earlierFirst) \/\/ sorts the slice in place\n    for _, date := range dates {\n        fmt.Print(date.Format(\"Jan 2\"), \"; \")\n    }\n    fmt.Println()\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Mar 15; Jul 4; Dec 1;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Time.Compare<\/code> plugs straight into <code>slices.SortFunc<\/code>, as in our <a href=\"https:\/\/smitabharat.com\/blog\/go-sorting-programs\/\">Go sorting programs<\/a>. The helper returns a negative number when the first date is earlier.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"time\"\n)\n\nfunc main() {\n    for _, year := range []int{2024, 2026, 2100} {\n        \/\/ Try to build 29 February in this year.\n        feb29 := time.Date(year, 2, 29, 0, 0, 0, 0, time.UTC)\n        fmt.Println(year, feb29.Month() == time.February)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>2024 true\n2026 false\n2100 false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is a neat leap year check. If 29 February does not exist, <code>time.Date<\/code> moves it to 1 March, so the month is no longer February.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Subscriptions are a classic use of Go date and time programs. Write a program that takes a subscription start date and a plan length in months, then prints the end date and how many days are left from a fixed &#8220;today&#8221; date. Hint: use <code>AddDate(0, months, 0)<\/code> for the end date and <code>Sub<\/code> divided by 24 hours for days left.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/time\">time package documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/time#pkg-constants\">time package: format layout constants<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/tour\/flowcontrol\/10\">A Tour of Go: Switch with time<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go date and time programs use <code>time.Time<\/code> for moments and <code>time.Duration<\/code> for lengths.<\/li>\n\n\n<li>Layouts use the reference time <code>2006-01-02 15:04:05<\/code>, not codes like YYYY.<\/li>\n\n\n<li><code>AddDate<\/code> handles calendar maths, while <code>Add<\/code> and <code>Sub<\/code> work with durations.<\/li>\n\n\n<li>Compare times with <code>Before<\/code>, <code>After<\/code>, <code>Equal<\/code> or <code>Compare<\/code>, never with <code>==<\/code>.<\/li>\n\n\n<li>Store times in UTC and convert with <code>In<\/code> or <code>LoadLocation<\/code> when you show them.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">That completes Level 4 of our Go programs series. Coming soon: Level 5, starting with Go file programs that read, write and count lines in files. Until then, revise with the <a href=\"https:\/\/smitabharat.com\/blog\/go-time-package-examples\/\">Go time package guide<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go date and time programs work with dates, clocks and durations, such as showing an order date, finding someone&#8217;s age or counting days until&hellip;<\/p>\n","protected":false},"author":1,"featured_media":785,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[106],"tags":[96,95,11,104,118],"swapz_series":[],"class_list":["post-810","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-programs","tag-beginner","tag-go-interview-questions","tag-go-lang","tag-go-programs","tag-go-time-package"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Date and Time Programs: Format, Parse, Zones<\/title>\n<meta name=\"description\" content=\"Go date and time programs with output: format and parse dates, add days, age calculator, durations and time zones, plus time interview questions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Date and Time Programs: Format, Parse, Zones\" \/>\n<meta property=\"og:description\" content=\"Go date and time programs with output: format and parse dates, add days, age calculator, durations and time zones, plus time interview questions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-08T07:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-28T19:59:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-date-time-programs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-date-time-programs\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Date and Time Programs: Format, Parse, Age and Time Zones\",\"datePublished\":\"2026-10-08T07:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-date-time-programs\\\/\"},\"wordCount\":1805,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-date-time-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-date-time-programs-featured.png\",\"keywords\":[\"Beginner\",\"Go Interview Questions\",\"Go Lang\",\"Go Programs\",\"Go Time Package\"],\"articleSection\":[\"Go Programs\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-date-time-programs\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-date-time-programs\\\/\",\"name\":\"Go Date and Time Programs: Format, Parse, Zones\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-date-time-programs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-date-time-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-date-time-programs-featured.png\",\"datePublished\":\"2026-10-08T07:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:31+00:00\",\"description\":\"Go date and time programs with output: format and parse dates, add days, age calculator, durations and time zones, plus time interview questions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-date-time-programs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-date-time-programs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-date-time-programs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-date-time-programs-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-date-time-programs-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Date and Time Programs featured image: formatted dates, age and time zones\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-date-time-programs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Date and Time Programs: Format, Parse, Age and Time Zones\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Date and Time Programs: Format, Parse, Zones","description":"Go date and time programs with output: format and parse dates, add days, age calculator, durations and time zones, plus time interview questions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/","og_locale":"en_US","og_type":"article","og_title":"Go Date and Time Programs: Format, Parse, Zones","og_description":"Go date and time programs with output: format and parse dates, add days, age calculator, durations and time zones, plus time interview questions.","og_url":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-08T07:30:00+00:00","article_modified_time":"2026-11-28T19:59:31+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Date and Time Programs: Format, Parse, Age and Time Zones","datePublished":"2026-10-08T07:30:00+00:00","dateModified":"2026-11-28T19:59:31+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/"},"wordCount":1805,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-featured.png","keywords":["Beginner","Go Interview Questions","Go Lang","Go Programs","Go Time Package"],"articleSection":["Go Programs"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/","url":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/","name":"Go Date and Time Programs: Format, Parse, Zones","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-featured.png","datePublished":"2026-10-08T07:30:00+00:00","dateModified":"2026-11-28T19:59:31+00:00","description":"Go date and time programs with output: format and parse dates, add days, age calculator, durations and time zones, plus time interview questions.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-date-time-programs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-date-time-programs-featured.png","width":2400,"height":1260,"caption":"Go Date and Time Programs featured image: formatted dates, age and time zones"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-date-time-programs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Date and Time Programs: Format, Parse, Age and Time Zones"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=810"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/810\/revisions"}],"predecessor-version":[{"id":891,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/810\/revisions\/891"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/785"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=810"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}