JS processing Date & string format to convert each other

Source: Internet
Author: User

I've been looking for some ways to get the system date and the date & string format to convert each other, but the overall self-feeling is the following way more appropriate.

If there is a better way, hope that we have a lot of comments and exchanges, thank you!

2016 wrote once, but just sent a bit of code, yesterday think of the blog park, log in after viewing the damage can not be opened, I said very sorry,

Also look ahead to see the friends do not open a lot of forgive!

"No forwarding sharing without my permission, thank you!" 】

--------------------------------------------------------------------------------------------------------------- --

Convert string to date format:

Page Submission Date Processing

function Send () {

var EndDate = window.document.getElementById ("EndDate"). Value;

Convert a date to a string

var enddatetx = enddate.tostring ();

if (Enddatetx! = "") {

Date Style (YYYY/MM/DD) converted to string style (YYYY-MM-DD)

Window.document.getElementById ("Enddatetx"). Value = Enddatetx.replace (/\//g, "-");

}else{

Window.document.getElementById ("Enddatetx"). Value = "";

}

}

--------------------------------------------------------------------------------------------------------------- --

Date converted to string format:

The Echo load date, provided that the Date field in the page has its field formatted as date and the style is YYYY/MM/DD

function OnLoad () {

var EndDate = window.document.getElementById ("EndDate"). Value;

if (EndDate! = "") {

string format (YYYY-MM-DD) to convert to date format (YYYY/MM/DD)

var Enddaterx = Enddate.replace (/-/g, "/");

Window.document.getElementById ("Enddaterx"). Value = Enddaterx;

}else{

Window.document.getElementById ("Enddaterx"). Value = "";

}

}

Note: replace () application and precautions, you can go to view the relevant information, there are many online.

JS processing Date & string format to convert each other

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.