Avatar of sidwelle
Flag for United States of America

asked on 

Convert 'Long Date' to HL7 Date 'yyyyMMddhhmmss'

I need to convert a 'Long Date' to HL7 date, and I was trying to do it with some of functions available and not appending each component of the date and time independently.
Input format: 'Mon May 21, 2018 11:52 PM'
Output format: 'yyyyMMddhhmmss'

      // example: Mon May 21, 2018 11:52 PM
      var d1 = new Date("Mon May 21, 2018 11:52 PM");    
      // var d = org.joda.time.format.DateTimeFormat.forPattern('MM/dd/yyyy').parseDateTime(ServDatetime);

      var dt = d1.toLocaleDateString() + " " + d1.toLocaleTimeString().replace(" CDT", "").replace(" PM", "");
      var d2 = org.joda.time.format.DateTimeFormat.forPattern('DDD MMM dd, yyyy hh:mm').parseDateTime(dt);    // This line fails !!, not sure how to set this up ??
      alert('New Date: ' + d2.toString());

Avatar of undefined
Last Comment

8/22/2022 - Mon