我想将日期时间转换为指定格式
Wed Aug 01 2012 14:37:50 GMT+0530 (India Standard Time)
实际上我想在网页上使用 Jquery 显示计时器。所以我尝试了一些我知道的格式。并从http://www.dotnetperls.com/datetime-format中找到了一些但它们都没有返回我需要的结果。实际上我必须从服务器打发时间所以我尝试了以下代码。 代码背后
protected void Button3_Click(object sender, EventArgs e)
{
//string hello = DateTime.UtcNow.ToString();
string hello = String.Format("{0:F}", DateTime.UtcNow);
DateTime.UtcNow.ToString("");
ScriptManager.RegisterStartupScript(this, this.GetType(), "hdrEmpty1", "show(" + hello + ")", true);
}
jQuery
function show(datetime) {
alert(datetime);
var Digital = datetime //new Date()
var hours = Digital.getHours()
var minutes = Digital.getMinutes()
var seconds = Digital.getSeconds()
var dn = "AM"
if (hours > 12) {
dn = "PM"
hours = hours - 12
}
if (hours == 0)
hours = 12
if (minutes <= 9)
minutes = "0" + minutes
if (seconds <= 9)
seconds = "0" + seconds
document.getElementById('<%= Label1.ClientID %>').innerHTML = hours + ":" + minutes + ":" + seconds + " " + dn
setTimeout("show()", 1000)
}