开发者

convert javascript time to asp.net DateTime.Now

I'm trying to convert the javascript date to ASP.NET's DateTime.Now

var todaysDate = new Date();
document.getElementById('hdnDate').value = todaysDate.toString();


private void ConvertToDotNetDateTime()
{
    DateTime myDate = (DateTim开发者_Go百科e)hdnDate.Value; ??? ? //bit lost here
}


JavaScript:

document.getElementById('hdnDate').value = (new Date()).format('dd/MM/yyyy HH:mm:ss');

in C#:

CultureInfo provider = CultureInfo.InvariantCulture;

string date = hfClientDate.Value;

string format = "dd/MM/yyyy HH:mm:ss";

DateTime dt = DateTime.ParseExact(date, format, provider);

Hope this helps someone.


You can use DateTime.ParseExact to convert the date to DateTime.Now

You can check the Example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜