Javascript date format like ISO but local

前端 未结 7 1503
广开言路
广开言路 2020-12-11 00:06

how do I format a javascript date like ISO format, but in local time?

with myDate.toISOString() I am getting the time as: \"2012-09-13T19:12:23.826Z\"

7条回答
  •  难免孤独
    2020-12-11 00:42

    AFAIK you can't format dates in javascript (without using external libraries). The best you could do is "format it yourself". I mean:

    var date = new Date();
    var year = date.getFullYear();
    var month = date......
    
    
    var ISOdate = year + "-" + month + "-" + .... ;
    

    But there are some good libraries that will let you format dates! (read "format" as in library.getDate("YYYY-MM-DD.........");)

    EDIT:

    Moment.js seems the thing you're looking for: http://momentjs.com/

提交回复
热议问题