JS formatted output: Practical tips: JS format Date Output

Source: Internet
Author: User
Tags date format object split string format

In Javaweb application, the date returned through the AJAX query is similar to the following "2010-08-01 18:22:00.0", how to according to the hope of the results show that often cost some trouble, here provide two methods to solve this problem, for reference only. The format method is not perfect, but it can satisfy most of the needs.
One, the effect chart

Second, the original code
1. Analytic method
* Output time in string format as standard Date object
* @param stringdate format such as: Var stringdate= "2010-08-01 18:22:00.0";
var parsedate=function (stringdate) {
var s=stringdate.substr (0, Stringdate.lastindexof ("."));
var ss=s.split ("");
var tms=ss[1];
var sss=ss[0].split ("-");
var y=sss[0];
var m=sss[1];
var d=sss[2];
var mm= "the";
if (m== "01") {
if (m== "02") {
Mm= "Feb";
if (m== "03") {
Mm= "Mar";
if (m== "04") {
Mm= "APR";
if (m== "05") {
Mm= "may";
if (m== "06") {
mm= "June";
if (m== "07") {
mm= "June";
if (m== "08") {
Mm= "Aug";
if (m== "09") {
Mm= "Sep";
if (m== "10") {
Mm= "OCT";
if (m== "11") {
Mm= "Nov";
if (m== "12") {
Mm= "Dec";
var dt=new Date (mm+ "+d+", "+y+" "+tms");
return DT;
2. Format method
* Default Output "September 1" format
* @param Date Date Object
* @param format allowable value: YYYY year mm month DD Day TT time MM minute SS seconds week or part of it
var formatdate=function (Date,format) {
function today {
Switch (day) {
Case 0:
Day = "Sunday";
Case 1:
Day = "Monday";
Case 2:
Day = "Tuesday"; This article links http://www.cxybl.com/html/wyzz/JavaScript_Ajax/20121120/34056.html

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.