MOCKSTACKS
EN
Questions And Answers

More Tutorials









Javascript Convert to a string format

Convert to String


var date1 = new Date();
date1.toString();

Output

"Fri Apr 15 2016 07:48:48 GMT-0400 (Eastern Daylight Time)"

Convert to Time String


var date1 = new Date();
date1.toTimeString();

Output

"07:48:48 GMT-0400 (Eastern Daylight Time)"

Convert to Date String


var date1 = new Date();
date1.toDateString();

Output

"Thu Apr 14 2016"

Convert to UTC String


var date1 = new Date();
date1.toUTCString();

Output

: "Fri, 15 Apr 2016 11:48:48 GMT"

Convert to ISO String


var date1 = new Date();
date1.toISOString();

Output

"2016-04-14T23:49:08.596Z"

Convert to GMT String


var date1 = new Date();
date1.toGMTString();

Output

"Thu, 14 Apr 2016 23:49:08 GMT"

This function has been marked as deprecated so some browsers may not support it in the future. It is suggested to use toUTCString() instead.

Convert to Locale Date String


var date1 = new Date();
date1.toLocaleDateString();

Output

"4/14/2016"

would attempt to print the string in the Chinese locale using United States English as a fallback. The options parameter can be used to provide specific formatting. For example:


var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
date1.toLocaleDateString([], options);

Output

"Thursday, April 14, 2016".


Conclusion

In this page (written and validated by ) you learned about Javascript Convert to a string format . What's Next? If you are interested in completing Javascript tutorial, your next topic will be learning about: Javascript Formatting date.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.