Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How JavaScript converts a date to a string

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report