Parsing time to string results in date
Parsing time to string results in date
I'm trying to parse an excel sheet where one of the columns is time viz. 5:15PM
, 7:10AM
. I can store these values successfully as strings just by doing myTimeVar.toString()
.
5:15PM
7:10AM
myTimeVar.toString()
However, when the time value has a space
in between e.g. 5:15 PM
and 7:10 AM
, the toString()
method returns a full blown date object as string. For instance, myTimeVar.toString()
prints Sat Dec 30 1899 16:15:00 GMT-0500 (Eastern Standard Time)
where myTimeVar
is 5:15 PM
(with a space in between time and PM).
space
5:15 PM
7:10 AM
toString()
myTimeVar.toString()
Sat Dec 30 1899 16:15:00 GMT-0500 (Eastern Standard Time)
myTimeVar
5:15 PM
I even tried avoiding toString()
and using String()
but no success.
toString()
String()
Edit: I'm using node and convert-excel-to-json to do the parsing.
Edit 2: Node treats 5:15PM
(no space) as a string but 5:15 PM
(with space) as an object.
5:15PM
5:15 PM
@JaredSmith, yes I'm using node and npmjs.com/package/convert-excel-to-json for parsing
– Hyperbola
Aug 30 at 22:53
If you are using the
toString()
method, it's obvious that the original data type is not string. So what's it?– Cristian Traìna
Aug 30 at 22:53
toString()
@CristianTraìna Node is treating
5:15 PM
as an object because of the colon. But node treats 5:15PM
as string.– Hyperbola
Aug 30 at 22:56
5:15 PM
5:15PM
Then it is a JavaScript Date object. It sounds though like your conversion library is improperly converting those values though, unless it's really supposed to be from the 1800's. I would guess it's a bug in that library, you might actually have more luck filing a github issue.
– Jared Smith
Aug 31 at 13:15
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
How are you parsing it? What is the context? Node.js?
– Jared Smith
Aug 30 at 22:47