0

From service I get date string in format 'yyyy-mm-dd' (eb, '2017-09-14')

In JavaScript, I convert this string to Date like as mentioned below:

new Date('2017-09-14')

It works just fine. But I am facing problem in different time zones. For example

In EST Timezone: Wed Sep 13 2017 20:00:00 GMT-0400 (Eastern Daylight Time) and

In IST Timezone: Thu Sep 14 2017 05:30:00 GMT+0530 (India Standard Time)

Is there a way to convert it to the same date e.g. Sep 14, 2017

Omid Nikrah
  • 2,307
  • 3
  • 12
  • 27
ConfusedDeveloper
  • 5,173
  • 3
  • 19
  • 31

1 Answers1

0

YOu can do it like this

var d=new Date(date value);
var actualDate=d.getDate();
var actualMonth=d.getMonth()+1;
var actualYear=d.getFullYear();    
var formattedDate=actualDate + '/' + actualMonth + '/' + actualYear;

You can save it to any format

Exterminator
  • 1,193
  • 5
  • 14