Get Current Time By Location

time.Time -> merupakan struct dan punya method

Method
Return

time.Now().Local()

time.Time

time.Now().Year()

Int

time.Now().Month()

Int

time.Now().Day()

Int

Contoh code untuk memperoleh waktu di lokasi saat ini

package main

import (
    "fmt"
    "time"
)

func main() {
	// return current local time
    	now := time.Now()
    	fmt.Println(now)

	fmt.Println(now.Year())
	fmt.Println(now.Month())
	fmt.Println(now.Day())
	fmt.Println(now.Format("02/01/2006 03:04 PM"))
	fmt.Println(now.Format("03:04 PM"))
	fmt.Println(now.Format("15:04"))
}

Contoh code untuk memperoleh waktu di suatu lokasi

Last updated