How to Use time.Time.Day() Function in Golang

Golang time.Time.Day() function is “used to check the day of the month in which the stated ‘t’ presents itself.”

Syntax

func (t Time) Day() int

Parameters

t: It is the stated time.

Return Value

The Day() function returns the day of the month in which the stated ‘t’ occurs.

Example 1: How to Use time.Time.Day() function

package main

import (
  "fmt"
  "time"
)

func main() {
  // Get the current time
  date := time.Date(2025, 12, 25, 0, 0, 0, 0, time.UTC)

  // Get the current day of the month
  day := date.Day()

  fmt.Println("Current Day:", day)
}

Output

Current Day: 25

Example 2: How to Get Current Day in Golang

To get the current day in Golang, you can use the “time.Time.Day()” function.

package main

import (
  "fmt"
  "time"
)

func main() {
  // Get the current time
  now := time.Now()

  // Get the current day of the month
  day := now.Day()

  fmt.Println("Current Day:", day)
}

Output

Current Day: 1

That’s it.

Leave a Comment