2

I have a time string:

2018-08-09T13:19:22.479522-05:00 

Parsing the string using:

parseDateTime(time, "yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX") 

Yields this result:

2018-08-09 14:27:21 

I'm -4 hours from GMT, so I get the hour difference, but why is the minute different?

Update: I'm certain the problem is the 6 digit millisecond, but can ColdFusion process this? As of now, I'm using left() and right() to get around the issue.

Community
  • 1
  • 1
Patrick Schomburg
  • 2,494
  • 1
  • 18
  • 46
  • Note: Patrick discovered that the problem was related to the 6-digit millisecond in the mask. I deleted my (wrong) answer, which contained that discussion. – tgolisch Apr 12 '19 at 19:43
  • 2
    *can coldfusion process this* Nope. java.util.Date (which is what CF uses along with SimpleDateFormat) don't support that level of granularity. That's why the time is being misinterpreted. https://stackoverflow.com/questions/30135025/java-date-parsing-with-microsecond-or-nanosecond-accuracy – SOS Apr 14 '19 at 18:01

1 Answers1

1

why is the minute different?

It's because java.util.Date (which is what ColdFusion uses along with SimpleDateFormat) doesn't handle microseconds, only milliseconds. The mask ".SSSSSS" only allows CF/Java to extract the extra digits, but once extracted that whole value is treated as a number of milliseconds:

  • 479522 milliseconds ... or
  • 479.522 seconds ... or
  • 7 minutes, 59 seconds and 522 milliseconds

So in this case, instead of adding fractions of a second, it increases the final time by nearly eight minutes. That's why the result isn't quite what you expected.

Base Time  14:19:22.000
   +               .522 milliseconds
   +             59.000 seconds
   +           7:00.000 minutes  
   ====================
Final Time 14:27:21.522

tl;dr;

ParseDateTime() can't process that particular date/time string, so you'll have to DIY.

SOS
  • 6,430
  • 2
  • 11
  • 29