#1
| |||
| |||
js format date string |
#3
| |||
| |||
Re: js format date string
I will tell you way to use JavaScript programming language for formatting Date and Time Strings, so that you can apply the same. The following example shows how to use to Locale Date String and to Locale Time String to format dates and times. The first parameter passed to these methods is a locale value, such as "en-us". The second parameter, where present, specifies formatting options, such as the long form for the weekday. Example var date = new Date(Date.UTC(2013, 1, 1, 14, 0, 0)); var options = { weekday: "long", year: "numeric", month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" }; document.write(date.toLocaleDateString("en-US")); document.write(date.toLocaleTimeString("en-us", options)); document.write(date.toLocaleDateString("ja-JP")); document.write(date.toLocaleTimeString("ja-JP", options)); // Output: // 2/1/2013 // Friday, Feb 1, 2013 06:00 AM // 2013年2月1日 // 2013年2月1日 金曜日 06:00 Formatting Dates Before Internet Explorer 11, JavaScript did not have specific methods to format dates and times. To provide your own date formatting for previous browser versions, use the getDay Method (Date), getDate Method (Date), getMonth Method (Date), and getFullYear Method (Date) methods. (The getYear Method (Date) is obsolete and should not be used.) var myDate = new Date("February 3, 2001"); var myDate = new Date("February 3 2001"); document.write((myDate.getMonth() + 1) + "-" + myDate.getDate() + "-" + myDate.getFullYear()); document.write("<br/>"); document.write((myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myDate.getFullYear()); //Output: // 2-3-2001 // 2/3/2001 |
|