Convert Date/Time in Gmt to Est in JavaScript

How to convert a time from GMT to EST

    try {
DateFormat gmtFormat = new SimpleDateFormat();
TimeZone estTime = TimeZone.getTimeZone("EST");
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
System.out.println("EST Time: " + gmtFormat.format(sdf.parse("20140508063630")));
} catch (ParseException e) {

How to set date always to eastern time regardless of user's time zone

You can easily take care of the timezone offset by using the getTimezoneOffset() function in Javascript. For example,

var dt = new Date(1458619200000);
console.log(dt); // Gives Tue Mar 22 2016 09:30:00 GMT+0530 (IST)

console.log(dt); // Gives Tue Mar 22 2016 04:00:00 GMT+0530 (IST)

var offset = -300; //Timezone offset for EST in minutes.
var estDate = new Date(dt.getTime() + offset*60*1000);
console.log(estDate); //Gives Mon Mar 21 2016 23:00:00 GMT+0530 (IST)

Though, the locale string represented at the back will not change. The source of this answer is in this post. Hope this helps!

Is it possible to convert timestamp to date and time using GMT offset as timezone in moment.js?

UTC and GMT indicate the same time. Convert the Local time to UTC and then use utcOffset.

var m = moment(new Date()).utc().utcOffset("-06:00").format("YYYY-MM-DD HH:mm:ss z");
console.log("UTC-06:00 -> " + m);
var m = moment(new Date()).utc().utcOffset("-05:00").format("YYYY-MM-DD HH:mm:ss z");
console.log("UTC-05:00 -> " + m);
var m = moment(new Date()).utc().utcOffset("-04:00").format("YYYY-MM-DD HH:mm:ss z");
console.log("UTC-04:00 -> " + m);
<script src=""></script>

Convert GMT time to local time

This worked for me:

var strDateTime = "Fri, 18 Oct 2013 11:38:23 GMT";
var myDate = new Date(strDateTime);

Please take a look at for all further date time manipulations, from the date object myDate.

Related Topics

Leave a reply