convert gmt to samoa time in javascript

To convert GMT to Samoa Time in JavaScript, you can use the getTimezoneOffset() method of the Date object to get the time zone offset in minutes based on the user's current local settings.

Then you can apply the Samoa Timezone offset of UTC+13:00 to the current time to get the converted time. Here's an example code snippet:

index.tsx
// get current UTC time
var now = new Date();

// get time zone offset in minutes
var timezoneOffset = now.getTimezoneOffset();

// convert to Samoa Timezone (UTC+13:00)
var samoaTime = new Date(now.getTime() + (timezoneOffset + 780) * 60 * 1000);

// format Samoa Time as a string
var samoaTimeString = samoaTime.toLocaleString();
332 chars
12 lines

In this example, 780 is added to the timezone offset (in minutes) to convert from GMT to Samoa Time.

Note that the toLocaleString() method is used to format the Samoa Time as a string using the user's local settings. You can also use other methods to format the date and time as needed.

gistlibby LogSnag