Sending javascript date to date variable vb.net

I need to pass javascript date value to vb.net function.

Iam method using now: convert javascript date to string store it in hidden field extract string from hidden field to server code and parse it using date.parse

the problem is javascript dateformats

toString () - Sat 4 Apr 22:19:00 UTC + 0530 2009

toDateString () - Sat Apr 4, 2009

toLocaleString () - Saturday, April 04, 2009 10:19:00 PM

does not match vb date format. I get the error that its unsurpassed.

Thanks in advance for your help

+3
source share
5 answers

ToLocaleString , , , .

: -

  DateTime d = DateTime.ParseExact(sInput, "ddd MMM d HH: mm: ss UTCzzzz yyyy", CultureInfo.InvariantCulture); a >

( ECMA , toString).

, Date Javascript - 1 1970 . , .valueOf date . Int32.Parse , TimeSpan DateTime 1 1970 . 00:00:00 UTC + 0000.

int milliseconds = Int32.Parse(inputString);
TimeSpan t = TimeSpan.FromMilliseconds(milliseconds);
DateTime base = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
DateTime result = base + t;
+5

Javascript , VB.net.

Public Function ConvertJavaScriptDate(ByVal d as String) As Date
  Return Date.Parse(d)
End Function

- CType (d, Date). CType - , Date.

JavaScript VB.Net , , , .

+1

, toLocaleString().

toLocaleString() , Date.Parse().

.

+1

This is simply a problem with the formation of the date and time. You can view this post for more details. How can we solve the datetime problem by moving the access database from the production server to live

0
source

You can also use DateTime.ParseExact()to specify the VB code exactly what the next line should look like.

0
source

Source: https://habr.com/ru/post/1705905/


All Articles