Golang - How to get the current date and time with timestamp in local and other timezones? Code Example

The code for How to get the current date and time with timestamp in local and other timezones?

// Go language program to get the current date and time 
// with timestamp in local and other timezones

package main

import (
	"fmt"
	"time"
)

func main() {

	// Get the local time using time.Now()
	timeObj := time.Now()
	
	// print location and local time
	loc, error := time.LoadLocation("America/New_York")
	if error != nil {
		fmt.Println(error)
	}
	
	// America/New_York
	fmt.Println("Location : ", loc, " Time : ", timeObj.In(loc))
}

/*
Output:
Location :  America/New_York  Time :  2023-03-01 02:44:39.652205714 -0500 EST
*/
Code by IncludeHelp, on March 1, 2023 07:45

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.