dcsimg
Results 1 to 10 of 10

Thread: parse date jquery

  1. #1

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,625

    parse date jquery

    Hi
    I'm trying to parse a date of string to a jquery with newtonsoft json
    If i do this: .DateOfBirth = "1993-04-25" I get:
    Code:
    There was an error deserializing the object of type WSVistaWebClient.ServiceContracts.CreateMemberRequest. DateTime content '1953-04-25' does not start with '\/Date(' and end with ')\/' as required for JSON.
    System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type WSVistaWebClient.ServiceContracts.CreateMemberRequest. DateTime content '1953-04-25' does not start with '\/Date(' and end with ')\/' as required for JSON. ---> System.FormatException: DateTime content '1953-04-25' does not start with '\/Date(' and end with ')\/' as required for JSON.
    If i do this:
    Code:
      Dim DateT = New DateTime(2000, 8, 7)
            Dim Timestamp As Long = DateT.Ticks - New DateTime(1970, 1, 1).Ticks
            Timestamp /= TimeSpan.TicksPerSecond
            LoyaltyCreateMember.LoyaltyMember.DateOfBirth = "/Date('" & Timestamp & "')/"
    I get:
    Code:
     There was an error deserializing the object of type WSVistaWebClient.ServiceContracts.CreateMemberRequest. The value ''965606400'' cannot be parsed as the type 'Int64'.
    System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type WSVistaWebClient.ServiceContracts.CreateMemberRequest. The value ''965606400'' cannot be parsed as the type 'Int64'. ---> System.Xml.XmlException: The value ''965606400'' cannot be parsed as the type 'Int64'. ---> System.FormatException: Input string was not in a correct format.
    if i do
    DateOfBirth = "/Date(1198908717056)/"

    i get

    Code:
     ValueType 'System.DateTime' cannot be null.
    System.Runtime.Serialization.SerializationException: ValueType 'System.DateTime' cannot be null.
    ?
    Any thoughts?
    Slow as hell.

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,428

    Re: parse date jquery

    try like this

    Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          
            Dim temp = New DateTime(2008, 8, 7, 12, 15, 12)
            Dim tempDateTime As DateTime = DateTime.Parse(temp.ToString)
            Dim mResult As String = tempDateTime.ToString("yyyy-MM-dd HH:mm:ss")
            MsgBox(mResult)
        End Sub
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,625

    Re: parse date jquery

    This will not work.
    I think it needs to be timestamped like so: /Date(1198908717056)/

    The problem is how to get a timestamp from a reference date (from i think 1970-01-01) .
    I have done the opposite and it works.
    Maybe a the reverse will work?

    Code:
     Public Function DeserializeTime(ByVal vdate As String) As DateTime
    
                Dim strvdate As String = ""
    
                                     End Sub)
    
                For Each c As Char In vdate
                    If IsNumeric(c) Then
                        strvdate = strvdate + c
                    End If
                Next
    
                Dim dtest As DateTime = "1/1/1970"
                Try
                    dtest = dtest + TimeSpan.FromMilliseconds(Convert.ToDouble(strdate))
                Catch ex As Exception
                    Return "1/1/0002"
                End Try
    
                Return dtest
            End Function
    Slow as hell.

  4. #4

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,625

    Re: parse date jquery

    I think there is a bug in the program they provided me with. When I do the opposite from another of their calls, I get a string like so: "/Date(948412800000)/"
    So I'm trying to do the opposite a set a string like so:
    Code:
       Dim dat As New DateTime(2000, 1, 21)
            uTime = (dat - New DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds
            LoyaltyCreateMember.LoyaltyMember.DateOfBirth = "/Date(" & uTime & ")/" ' "/Date(948412800000)/"
    It should work as getting the date is the exact same string when setting the date but it doesn't.
    So if there isn't any other idea I should probably report it as a bug to them.
    Slow as hell.

  5. #5
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,428

    Re: parse date jquery

    somebody else in this Link/thread has/had the same problem

    https://stackoverflow.com/questions/...soft-json-date
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  6. #6

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,625

    Re: parse date jquery

    I don't know man, I just don't know. I've tried everything.

    The calling values look like this:
    Name:  Clipboard01.jpg
Views: 52
Size:  21.2 KB

    So as you can see the date is what I'm trying also to pass, but it fails.
    Slow as hell.

  7. #7
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,282

    Re: parse date jquery

    I don't really understand what you are trying to do. Have you created an Instance of a Class that contains Date Properties, and are you using NewtonSoft Json.Net to serialize it to JSON which can then sent to a remote server? Is it the remote server that is giving you the error message about the Date format being wrong?

    If so, although I've never done it before, the first thing I'd try would be to force Json.Net to do the Date conversion for you.

    So with this simple test Class that has a Date Property:
    Code:
    Public Class Test
        Public Property DateOfBirth As Date
    End Class
    I'd create an instance, set the Date Property value as normal (human readable date), and use a JsonSerializerSettings that specifies the required date format for Json.Net:
    Code:
    Private Sub Button1_Click(sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
        Dim myTest As New Test With {.DateOfBirth = #2000/01/21#}
    
        Dim msDateFormatSettings = New JsonSerializerSettings With {.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat}
        Dim json = JsonConvert.SerializeObject(myTest, msDateFormatSettings)
    
        MsgBox(json)
    
    End Sub
    And that spits out the following JSON:
    {"DateOfBirth":"\/Date(948412800000+0000)\/"}

    Apologies if I've misunderstood the problem.

  8. #8
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,428

    Re: parse date jquery

    try..

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          
        Dim myDate = New DateTime(1970, 1, 1).AddMilliseconds(1198908717056)
            MsgBox(myDate)
            Debug.Print(myDate) '= 29.12.2007 06:11:57
        End Sub
    Last edited by ChrisE; Feb 7th, 2020 at 09:05 AM.
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  9. #9

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,625

    Re: parse date jquery

    @ Inferrd
    I have my own serializer using NewtonSoft so the serializing is correct. The issue is the date format.
    I've talked with the company and they said that the correct data need to be passed is "/Date(<Difference in milliseconds>)/" , they also said that since I have passed this, it should work, but it does not, so they will take a look. It's probably a bug on their side.
    Just waiting an answer from them.
    Thanks
    Slow as hell.

  10. #10

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,625

    Re: parse date jquery

    Got it.
    Had to open their dll myself.
    Apparently the issue was that I also needed to provide an expiry date?!?!

    So the message was for the expiration date not set and not the birthrate!

    SO CAN YOU FKN WRITE A BETTER RETURN RESULT?! LOST 3 DAYS ON THIS!

    Anyhow.
    Thanks.

    Edit. No mark thread resolve in my tools?!
    Slow as hell.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width