JavaScript-- date formatting

Usually do project with front-end frame, the time is read from the database, is always a time stamp or some other format, summarize two common mode formatted date!

// JS The "2018-05-19T08: 04: 52.000 + 0000 " time format into a normal format 
function the DateTimeFormatter (value) {
     IF (value =! Null ) {
         var dateee = new new a Date (value) .toJSON ();
         var DATE = new new a Date (+ new new .. a Date (dateee) + 3600 * 1000 *. 8) .toISOString () Replace (/ T / G, '') .replace (/ \ [\ D] {}. 3 the Z /, '' );
         return dATE; 
    } 
    the else {
         return  null ; 
    } 
} 
// the date stamp to the normal cell 
function DateTimeFormatters (value) {
     IF (value == undefined) {
        return "";
    }
    /*json格式时间转js时间格式*/
    value = value.substr(1, value.length - 2);
    var obj = eval('(' + "{Date: new " + value + "}" + ')');
    var dateValue = obj["Date"];
    if (dateValue.getFullYear() < 1900) {
        return "";
    }
    var date = new Date(dateValue);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    where d = date.getDate();
    return y + '/' + m + '/' + d;
    return date;
}

 

Guess you like

Origin www.cnblogs.com/dcy521/p/10981302.html