Date.parse(2/4/2011 9:34:48 AM)

后端 未结 3 629
北荒
北荒 2021-01-24 05:30

my input will be from a variable (Ticket.CreationDate) and will look like

2/4/2011 9:34:48 AM (it will vary of course)

Ideally I could pass in the variable as-i

3条回答
  •  梦谈多话
    2021-01-24 06:22

    I would suggest a combination of 2 different Date libraries I am aware of.

    The first, for parsing the date from a string, is DateJS. You can find it at http://www.datejs.com/. Your example parses with their library fine (once you include appropriate quote marks)

    // Results in Date object whose toString is:  
    //    Fri Feb 04 2011 09:34:48 GMT-0600 (Central Standard Time)
    Date.parse('2/4/2011 9:34:48 AM')
    

    The other library is for creating nicely formatted string values based on your date object. This can be found at http://blog.stevenlevithan.com/archives/date-time-format. For example, from that page:

    // Saturday, June 9th, 2007, 5:46:21 PM
    var now = new Date();
    dateFormat(now, "ffffdd, mmmm dS, yyyy, h:MM:ss TT");
    

提交回复
热议问题