locked
Converting String To Date Time RRS feed

  • Question

  • User1231829591 posted

    Suppose I have multiple pieces of strings taken from various input boxes on a form and I concatenate them together as shown below :

    "JAN" + " " + "09" + " " + "2018" + " " + "1:00 PM" + " " + "EST"

    Below is the resulting string 

    JAN 09 2018 1:00 PM EST

    I have looked at several javascript functions for converting a string to a date but none seem to be the one I need. Is it possible to convert the string above to a date object in javascript?

    Friday, April 6, 2018 4:01 AM

Answers

  • User-474980206 posted

    perfectly valid for javascript: 

       new Date('JAN 09 2018 1:00 PM EST') 

    note: if you display it, it will be converted to the local timezone. so at my place its:

      > new Date('JAN 09 2018 1:00 PM EST')
      < Tue Jan 09 2018 10:00:00 GMT-0800 (PST)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 6, 2018 9:55 PM