How JavaScript converts a date to a string
This article mainly introduces the relevant knowledge of "how JavaScript converts a date into a string". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to convert a date into a string by JavaScript" can help you solve the problem.
Convert a date to a string
Date () returns a string.
Date () / / returns Thu Jul 17 2014 15:38:19 GMT+0200 (W. Europe Daylight Time)
The global method String () converts the date object to a string.
String (new Date ()) / / returns Thu Jul 17 2014 15:38:19 GMT+0200 (W. Europe Daylight Time)
The Date method toString () has the same effect.
Example
Obj = new Date ()
Obj.toString () / / returns Thu Jul 17 2014 15:38:19 GMT+0200 (W. Europe Daylight Time)
Convert a string to a number
The global method Number () converts a string to a number.
A string contains numbers (such as "3.14") that are converted to numbers (such as 3.14).
The empty string is converted to 0.
Other strings are converted to NaN (not a number).
Number ("3.14") / / returns 3.14
Number ("") / / returns 0
Number ("") / / returns 0
Number ("99 88") / / returns NaN
That's all for "how JavaScript converts dates into strings". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.