2016-03-29 56 views

回答

0

入住這

function addZero(i) { 
    if (i < 10) { 
     i = "0" + i; 
    } 
    return i; 
} 

function myFunction() { 
    var d = new Date(); 
    var x = document.getElementById("demo"); 
    var h = addZero(d.getHours()); 
    var m = addZero(d.getMinutes()); 
    var s = addZero(d.getSeconds()); 
    x.innerHTML = h + ":" + m + ":" + s; 
} 


function formatDate(date) { 
    var d = new Date(date), 
     month = '' + (d.getMonth() + 1), 
     day = '' + d.getDate(), 
     year = d.getFullYear(), 
      h = addZero(d.getHours()), 
    m = addZero(d.getMinutes()), 
    s = addZero(d.getSeconds()); 

    if (month.length < 2) month = '0' + month; 
    if (day.length < 2) day = '0' + day; 

    return [year, month, day].join('-')+" "+[h,m,s].join(':'); 
} 
document.getElementById('res').innerHTML = formatDate('Mon March 28 2016 23:59:59 GMT -0600 (CENTRAL DAYLIGHT TIME)') ; 

jsfiddle.net

0

試試這個,

var d=your date; 
var actualDate=d.toLocaleString(); 

希望這有助於。

+0

localsestring是不會放棄與所有瀏覽器一致的結果。我可能不會使用localeString – JsLearner

+0

這不會因瀏覽器而異瀏覽器,儘管如果文化不同,它會有所不同 –

0

您可以使用日期和時間變換moment.js

0

試試這個,

在烏爾視圖,

columns.Bound("YOUR MODEL").Format(" 
{0:n6}").ClientTemplate("#=SAMPLEDATEDISPLAY#").Title("Sample Date"); 

在UR模式,

public Nullable<System.DateTime> SAMPLEDATE{ get; set; } 

    public string SAMPLEDATEDISPLAY{ get { return SAMPLEDATE.HasValue ? SAMPLEDATE.Value.ToString() : string.Empty; } } 

請反饋:)

相關問題