Milliseconds From 1970!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    #1

    Milliseconds From 1970!

    I have a value that represents the time in milliseconds passed since
    1970 00:00:00 GMT that I need to convert into a readable date e.g.

    1092364211773 = 13/08/2004 03:30:00 GMT

    Is this easily done or do I need to write my own function for this???
    If that's the case, does anyone have some code to do this???

    Thanks in advance

    Steve
  • Jay B. Harlow [MVP - Outlook]

    #2
    Re: Milliseconds From 1970!

    Steve,
    Have you tried the DateTime.AddMil liseconds method?

    Something like:

    Dim base As New DateTime(1970, 1, 1)
    Dim readableDate As DateTime = base.AddMillise conds(109236421 1773)
    Debug.WriteLine (readableDate, "Readable date")

    Hope this helps
    Jay

    "Steve" <google@valleyb oy.net> wrote in message
    news:7a0a0475.0 408130638.165af 096@posting.goo gle.com...[color=blue]
    > I have a value that represents the time in milliseconds passed since
    > 1970 00:00:00 GMT that I need to convert into a readable date e.g.
    >
    > 1092364211773 = 13/08/2004 03:30:00 GMT
    >
    > Is this easily done or do I need to write my own function for this???
    > If that's the case, does anyone have some code to do this???
    >
    > Thanks in advance
    >
    > Steve[/color]


    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Milliseconds From 1970!

      Steve <google@valleyb oy.net> wrote:[color=blue]
      > I have a value that represents the time in milliseconds passed since
      > 1970 00:00:00 GMT that I need to convert into a readable date e.g.
      >
      > 1092364211773 = 13/08/2004 03:30:00 GMT
      >
      > Is this easily done or do I need to write my own function for this???
      > If that's the case, does anyone have some code to do this???[/color]

      It's easy to create a DateTime for Jan 1st 1970, and a TimeSpan for
      however many milliseconds you've got - then just add one to the other.

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • Steve

        #4
        Re: Milliseconds From 1970!

        This is perfect, thank you so much...

        Steve
        [color=blue]
        >-----Original Message-----
        >Steve,
        >Have you tried the DateTime.AddMil liseconds method?
        >
        >Something like:
        >
        > Dim base As New DateTime(1970, 1, 1)
        > Dim readableDate As DateTime =[/color]
        base.AddMillise conds(109236421 1773)[color=blue]
        > Debug.WriteLine (readableDate, "Readable date")
        >
        >Hope this helps
        >Jay
        >
        >"Steve" <google@valleyb oy.net> wrote in message
        >news:7a0a0475. 0408130638.165a f096@posting.go ogle.com...[color=green]
        >> I have a value that represents the time in milliseconds[/color][/color]
        passed since[color=blue][color=green]
        >> 1970 00:00:00 GMT that I need to convert into a[/color][/color]
        readable date e.g.[color=blue][color=green]
        >>
        >> 1092364211773 = 13/08/2004 03:30:00 GMT
        >>
        >> Is this easily done or do I need to write my own[/color][/color]
        function for this???[color=blue][color=green]
        >> If that's the case, does anyone have some code to do[/color][/color]
        this???[color=blue][color=green]
        >>
        >> Thanks in advance
        >>
        >> Steve[/color]
        >
        >
        >.
        >[/color]

        Comment

        • Jay B. Harlow [MVP - Outlook]

          #5
          Re: Milliseconds From 1970!

          Steve,
          If you go the TimeSpan route as Jon suggests. You can use
          TimeSpan.FromMi lliseconds to get a TimeSpan with milliseconds in it.

          Dim base As New DateTime(1970, 1, 1)
          Dim ts As TimeSpan = TimeSpan.FromMi lliseconds(1092 364211773)
          Dim readableDate As DateTime = base.Add(ts)

          Debug.WriteLine (readableDate, "Readable date")

          I'm mentioning this as I "always" forget about the TimeSpan.From* methods...
          *shrug*

          Hope this helps
          Jay

          "Steve" <google@valleyb oy.net> wrote in message
          news:5c9401c481 48$7ea94f30$a60 1280a@phx.gbl.. .[color=blue]
          > This is perfect, thank you so much...
          >
          > Steve
          >[color=green]
          > >-----Original Message-----
          > >Steve,
          > >Have you tried the DateTime.AddMil liseconds method?
          > >
          > >Something like:
          > >
          > > Dim base As New DateTime(1970, 1, 1)
          > > Dim readableDate As DateTime =[/color]
          > base.AddMillise conds(109236421 1773)[color=green]
          > > Debug.WriteLine (readableDate, "Readable date")
          > >
          > >Hope this helps
          > >Jay
          > >
          > >"Steve" <google@valleyb oy.net> wrote in message
          > >news:7a0a0475. 0408130638.165a f096@posting.go ogle.com...[color=darkred]
          > >> I have a value that represents the time in milliseconds[/color][/color]
          > passed since[color=green][color=darkred]
          > >> 1970 00:00:00 GMT that I need to convert into a[/color][/color]
          > readable date e.g.[color=green][color=darkred]
          > >>
          > >> 1092364211773 = 13/08/2004 03:30:00 GMT
          > >>
          > >> Is this easily done or do I need to write my own[/color][/color]
          > function for this???[color=green][color=darkred]
          > >> If that's the case, does anyone have some code to do[/color][/color]
          > this???[color=green][color=darkred]
          > >>
          > >> Thanks in advance
          > >>
          > >> Steve[/color]
          > >
          > >
          > >.
          > >[/color][/color]


          Comment

          • Cowboy \(Gregory A. Beamer\) [MVP]

            #6
            Re: Milliseconds From 1970!

            You can set up a DateTime Structure for the date in 1970 and then use a
            TimeSpan object with the requisite number of milliseconds and add to the
            first DateTime to get another DateTime.

            Dim dt as DateTime = Convert.ToDateT ime("1/1/1970")

            'Check this next line to make sure it is in the millisecond value
            Dim ts As New TimeSpan(0,0,0, 0,1092364211773 )

            Dim dt as DateTime = dt + ts

            Something like that. Check the documentation if this blows chunks, but the
            theory is sound.

            --
            Gregory A. Beamer
            MVP; MCP: +I, SE, SD, DBA

            *************** *************** *************** ***
            Think Outside the Box!
            *************** *************** *************** ***
            "Steve" <google@valleyb oy.net> wrote in message
            news:7a0a0475.0 408130638.165af 096@posting.goo gle.com...[color=blue]
            > I have a value that represents the time in milliseconds passed since
            > 1970 00:00:00 GMT that I need to convert into a readable date e.g.
            >
            > 1092364211773 = 13/08/2004 03:30:00 GMT
            >
            > Is this easily done or do I need to write my own function for this???
            > If that's the case, does anyone have some code to do this???
            >
            > Thanks in advance
            >
            > Steve[/color]


            Comment

            • Cor Ligthert

              #7
              Re: Milliseconds From 1970!

              George,

              In my opinion it is better to use as Jay showed
              Dim base As New DateTime(1970, 1, 1)

              That is independent from the culture settings.
              (Assuming the time Steve is from the US however when others read this).

              Cor


              Comment

              Working...