469,281 Members | 2,450 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

Unix Time Stamp

Hi,

I am trying to replicate the Unix Timestamp,specifically 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)
Jul 19 '05 #1
5 14170
*Shahid Juma* wrote in microsoft.public.inetserver.asp.general:
I am trying to replicate the Unix Timestamp,specifically 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?


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

<script language="JScript" runat="server">
function GetUnixTime(strDate) {
if (strDate) {
return new Date(strDate).valueOf();
}
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/
Jul 19 '05 #2

"Andrew Urquhart" <us**************************@com.invalid> wrote in
message news:18***************@usenet.andrewu.co.uk...
*Shahid Juma* wrote in microsoft.public.inetserver.asp.general:
I am trying to replicate the Unix Timestamp,specifically 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?


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

<script language="JScript" runat="server">
function GetUnixTime(strDate) {
if (strDate) {
return new Date(strDate).valueOf();
}
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/


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
Jul 19 '05 #3
*Shahid Juma* wrote in microsoft.public.inetserver.asp.general:
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.
That's the difference between seconds and milliseconds
Is there any other way? Besides doing it this way?


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/
Jul 19 '05 #4
A follow up to this question...

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

Shahid

"Andrew Urquhart" <us**************************@com.invalid> wrote in
message news:1h****************@usenet.andrewu.co.uk...
*Shahid Juma* wrote in microsoft.public.inetserver.asp.general:
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.


That's the difference between seconds and milliseconds
Is there any other way? Besides doing it this way?


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/

Jul 19 '05 #5
*Shahid Juma* wrote:
A follow up to this question...

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


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(1096925521646); // 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.toUTCString();

For the list of date methods see:
http://msdn.microsoft.com/library/en...6jsobjdatemeth
--
Andrew Urquhart
- FAQ: http://www.aspfaq.com
- Archive:
http://www.google.com/groups?group=m...er.asp.general
- Contact: http://andrewu.co.uk/contact/
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Yang Li Ke | last post: by
1 post views Thread by lkrubner | last post: by
7 posts views Thread by Don | last post: by
reply views Thread by Shahid Juma | last post: by
6 posts views Thread by Mike Charney | last post: by
2 posts views Thread by Shane | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.