开发者

convert javascript time to asp.net DateTime.Now

开发者 https://www.devze.com 2023-01-15 00:10 出处:网络
I\'m trying to convert the javascript date to ASP.NET\'s DateTime.Now var todaysDate = new Date(); document.getElementById(\'hdnDate\').value = todaysDate.toString();

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

精彩评论

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