Unix Time Stamp

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

    Unix Time Stamp

    Hi,

    I am trying to replicate the Unix Timestamp,speci fically the function
    mktime() in Vbscript, ASP. I have the following so far:

    ThisTime = DateSerial(2004 , 9, 27) + TimeSerial(0, 0, 0)
    response.write DateDiff("s", "12/31/1969 00:00:00", ThisTime)

    This returns the timestamp: 1096329600, and when you decode that it comes
    to: 27 Sep 2004 20:00. I want to set the time too, ie. show for example: 27
    Sep 2004 16:15

    Any ideas?

    Thanks,
    Shahid
    (remove the words "REMOVETHIS " when replying to email address)


  • Andrew Urquhart

    #2
    Re: Unix Time Stamp

    *Shahid Juma* wrote in microsoft.publi c.inetserver.as p.general:[color=blue]
    > I am trying to replicate the Unix Timestamp,speci fically the function
    > mktime() in Vbscript, ASP. I have the following so far:
    >
    > ThisTime = DateSerial(2004 , 9, 27) + TimeSerial(0, 0, 0)
    > response.write DateDiff("s", "12/31/1969 00:00:00", ThisTime)
    >
    > This returns the timestamp: 1096329600, and when you decode that it comes
    > to: 27 Sep 2004 20:00. I want to set the time too, ie. show for example: 27
    > Sep 2004 16:15
    >
    > Any ideas?[/color]

    Why not just invoke a JScript function from within your VBScript since
    JScript dates follow the same Unix format (AFAIK)?

    <script language="JScri pt" runat="server">
    function GetUnixTime(str Date) {
    if (strDate) {
    return new Date(strDate).v alueOf();
    }
    else {
    return 0;
    }
    }
    </script>
    <%=GetUnixTime( "Tue, 28 Sep 2004 14:45:28 GMT")%>

    (not tested)
    --
    Andrew Urquhart
    - FAQ: http://www.aspfaq.com
    - Archive: http://andrewu.co.uk/r/?6 (Google Groups)
    - Contact me: http://andrewu.co.uk/contact/

    Comment

    • Shahid Juma

      #3
      Re: Unix Time Stamp


      "Andrew Urquhart" <useWebsiteInSi gnatureToReply@ com.invalid> wrote in
      message news:18yq7do640 lrv.dlg@usenet. andrewu.co.uk.. .[color=blue]
      > *Shahid Juma* wrote in microsoft.publi c.inetserver.as p.general:[color=green]
      > > I am trying to replicate the Unix Timestamp,speci fically the function
      > > mktime() in Vbscript, ASP. I have the following so far:
      > >
      > > ThisTime = DateSerial(2004 , 9, 27) + TimeSerial(0, 0, 0)
      > > response.write DateDiff("s", "12/31/1969 00:00:00", ThisTime)
      > >
      > > This returns the timestamp: 1096329600, and when you decode that it[/color][/color]
      comes[color=blue][color=green]
      > > to: 27 Sep 2004 20:00. I want to set the time too, ie. show for example:[/color][/color]
      27[color=blue][color=green]
      > > Sep 2004 16:15
      > >
      > > Any ideas?[/color]
      >
      > Why not just invoke a JScript function from within your VBScript since
      > JScript dates follow the same Unix format (AFAIK)?
      >
      > <script language="JScri pt" runat="server">
      > function GetUnixTime(str Date) {
      > if (strDate) {
      > return new Date(strDate).v alueOf();
      > }
      > else {
      > return 0;
      > }
      > }
      > </script>
      > <%=GetUnixTime( "Tue, 28 Sep 2004 14:45:28 GMT")%>
      >
      > (not tested)
      > --
      > Andrew Urquhart
      > - FAQ: http://www.aspfaq.com
      > - Archive: http://andrewu.co.uk/r/?6 (Google Groups)
      > - Contact me: http://andrewu.co.uk/contact/[/color]

      Thanks, that did work, however, it returns back a value that is 13 in
      length. In PHP,it returns it with length of 10. I just took the first 10 and
      it did work. Is there any other way? Besides doing it this way?

      Thanks,
      Shahid


      Comment

      • Andrew Urquhart

        #4
        Re: Unix Time Stamp

        *Shahid Juma* wrote in microsoft.publi c.inetserver.as p.general:[color=blue]
        > Thanks, that did work, however, it returns back a value that is 13 in
        > length. In PHP,it returns it with length of 10. I just took the first 10 and
        > it did work.[/color]

        That's the difference between seconds and milliseconds
        [color=blue]
        > Is there any other way? Besides doing it this way?[/color]


        --
        Andrew Urquhart
        - FAQ: http://www.aspfaq.com
        - Archive: http://andrewu.co.uk/r/?6 (Google Groups)
        - Contact me: http://andrewu.co.uk/contact/

        Comment

        • Shahid Juma

          #5
          Re: Unix Time Stamp

          A follow up to this question...

          How do I convert it back and print the date, basically decode it.

          Shahid

          "Andrew Urquhart" <useWebsiteInSi gnatureToReply@ com.invalid> wrote in
          message news:1hfttct3zx it3$.dlg@usenet .andrewu.co.uk. ..[color=blue]
          > *Shahid Juma* wrote in microsoft.publi c.inetserver.as p.general:[color=green]
          > > Thanks, that did work, however, it returns back a value that is 13 in
          > > length. In PHP,it returns it with length of 10. I just took the first 10[/color][/color]
          and[color=blue][color=green]
          > > it did work.[/color]
          >
          > That's the difference between seconds and milliseconds
          >[color=green]
          > > Is there any other way? Besides doing it this way?[/color]
          >
          > http://www.aspfaq.com/show.asp?id=2219
          > --
          > Andrew Urquhart
          > - FAQ: http://www.aspfaq.com
          > - Archive: http://andrewu.co.uk/r/?6 (Google Groups)
          > - Contact me: http://andrewu.co.uk/contact/[/color]


          Comment

          • Andrew Urquhart

            #6
            Re: Unix Time Stamp

            *Shahid Juma* wrote:[color=blue]
            > A follow up to this question...
            >
            > How do I convert it back and print the date, basically decode it.[/color]

            In JScript (and javascript) the date object can take a unix integer date
            as the constructor parameter in addition to the various string inputs.

            E.g.: var objDate = new Date(1096925521 646); // Argument is in ms, not s

            If your value is in seconds, multiple it first by 1000 to get the
            required milliseconds input value. After creating the date object you
            can format it using the plethora of available date methods. However,
            one of the quickest ways of getting a string result is to use:

            var strDate = objDate.toUTCSt ring();

            For the list of date methods see:

            --
            Andrew Urquhart
            - FAQ: http://www.aspfaq.com
            - Archive:

            - Contact: http://andrewu.co.uk/contact/

            Comment

            Working...