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
精彩评论