Format the following date into YYYY-mm-dd in JS

后端 未结 4 1185
礼貌的吻别
礼貌的吻别 2021-01-26 10:29

How would I go about converting following date:

Thu Feb 18 12:25:00 SGT 2016

into a format like \'2016-02-18\'?

I know,

  1. That, using a new
4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-26 11:12

    var date = "Thu Feb 18 12:25:00 SGT 2016";
    
    date = date.replace("SGT","GMT+0800") // replaces SGT with GMT+0800 because 
    singapore time is 8 hrs ahead than GMT timezone
    
    var newdate = new Date(Date.parse(date))
    
    var requiredDate = newdate.toLocaleDateString()

提交回复
热议问题