How to get current year in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, we are going to learn how to get the current year and print it in a golang console, here we will use the time package to get a year.

Basically, we will use the time.Now() method to get the current time, after that we use Year() method to get a current year.

So, let’s start coding…

package main
import (
  "fmt"
  "time"
)

func main() {
  currentYear := time.Now().Year();
	fmt.Print(currentYear)
}

When you run the above code you will get a current year in your golang console, let’s check the output.

get, current year, golang

Try it yourself

All the best 👍

Premium Content

You can get all the below premium content directly in your mail when you subscribe us

Books

Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

I'm working on some more Cheat Sheets book on Jquery, TypeScript, React js and for other languages. I will send it once it's completed.

Stay tuned working on React Js Cheat Sheets Book

Related Posts