To convert GMT to Australian Eastern Standard Time in TypeScript, we can use the toLocaleString()
method on the Date
object to display the date and time according to the Australian Eastern Standard Time zone.
index.ts279 chars8 lines
Here, we create a new Date
object to get the current date and time in GMT. We then use the toLocaleString()
method on this object to convert it to Australian Eastern Standard Time.
The toLocaleString()
method takes two parameters: the language code and an options object. In the options object, we specify the timeZone
property to 'Australia/Sydney'
to convert to the Australian Eastern Standard Time zone.
Finally, we log the converted date and time to the console in the format dd/mm/yyyy, hh:mm:ss am/pm
, where dd
represents the day, mm
represents the month, yyyy
represents the year, hh
represents the hour, mm
represents the minute, and am/pm
represents the meridian.
gistlibby LogSnag