Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Convert unix timestamp to date/time in a specified format

Reply
Thread Tools

Convert unix timestamp to date/time in a specified format

 
 
Andyza
Guest
Posts: n/a
 
      03-04-2009
The sUnixDate variable below contains a unix timestamp. I use the
VBScript DateAdd function to convert it to a date/time variable
whenever I want to display the date on my .asp pages.

sUnixDate = "1235999914"
sNewDate = DateAdd("s",sUnixDate,#1970/1/1#)

sNewDate now contains the date according to the regional settings on
the computer eg:

'3/2/2009 1:18:34'
or
'2009/03/02 01:18:34'

Is there a way to specify a format for the date that is independent of
the Regional Settings on the computer?
I want the date to always be returned and displayed in the yyyy/mm/dd
hh:mm:ss format.

Thanks.
 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      03-04-2009
Andyza wrote on 04 mrt 2009 in microsoft.public.inetserver.asp.general:

> sUnixDate = "1235999914"
> sNewDate = DateAdd("s",sUnixDate,#1970/1/1#)
>
> sNewDate now contains the date according to the regional settings on
> the computer eg:
>
> '3/2/2009 1:18:34'
> or
> '2009/03/02 01:18:34'


No, it does not.

sNewDate contains the date/time,
independent of the regional settings.

It does not contain the way it is transcribed into a string.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
 
Tim Slattery
Guest
Posts: n/a
 
      03-04-2009
"Evertjan." <(E-Mail Removed)> wrote:

>Andyza wrote on 04 mrt 2009 in microsoft.public.inetserver.asp.general:
>
>> sUnixDate = "1235999914"
>> sNewDate = DateAdd("s",sUnixDate,#1970/1/1#)
>>
>> sNewDate now contains the date according to the regional settings on
>> the computer eg:
>>
>> '3/2/2009 1:18:34'
>> or
>> '2009/03/02 01:18:34'

>
>No, it does not.
>
>sNewDate contains the date/time,
>independent of the regional settings.
>
>It does not contain the way it is transcribed into a string.


True, but it doesn't answer the question. VBScript's FormatDate
function can display a date in several formats, all of which refer to
the computer's regional settings. AFAIK, there's no way to specify how
you want the date to look independent of the regional settings.

I suppose you could write your own function to do the necessary
arithmetic on the date value and format it as you want.

--
Tim Slattery
MS MVP(Shell/User)
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://members.cox.net/slatteryt
 
Reply With Quote
 
DiamondEagle
Guest
Posts: n/a
 
      03-04-2009
On Mar 4, 5:30*pm, "Evertjan." <(E-Mail Removed)> wrote:
>
> No, it does not.
>
> sNewDate contains the date/time,
> independent of the regional settings.
>
> It does not contain the way it is transcribed into a string.


Thanks.
Is there a way to display the date/time in the yyyy/mm/dd
hh:mm:ss format?
 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      03-04-2009
DiamondEagle wrote:
> On Mar 4, 5:30 pm, "Evertjan." <(E-Mail Removed)> wrote:
>>
>> No, it does not.
>>
>> sNewDate contains the date/time,
>> independent of the regional settings.
>>
>> It does not contain the way it is transcribed into a string.

>
> Thanks.
> Is there a way to display the date/time in the yyyy/mm/dd
> hh:mm:ss format?


http://classicasp.aspfaq.com/date-ti...es-for-me.html

--
HTH,
Bob Barrows


 
Reply With Quote
 
DiamondEagle
Guest
Posts: n/a
 
      03-04-2009
On Mar 4, 9:38*pm, "Bob Barrows" <(E-Mail Removed)> wrote:
>
> http://classicasp.aspfaq.com/date-ti...ation/can-i-ma...
>


Thanks Bob.

This rought "first draft" seems to work for me:

Function pd(n, totalDigits)
if totalDigits > len(n) then
pd = String(totalDigits-len(n),"0") & n
else
pd = n
end if
End Function

sUnixDate = "1235999914"
sNewDate = DateAdd("s",sUnixDate,#1970/1/1#)
Response.Write("sNewDate : " & sNewDate & "<br>")
Response.Write(Year(sNewDate) & "/" & pd(Month(sNewDate),2) & "/" & pd
(Day(sNewDate),2))


Gives me: 2009/03/02
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      03-05-2009
Tim Slattery wrote on 04 mrt 2009 in
microsoft.public.inetserver.asp.general:

> "Evertjan." <(E-Mail Removed)> wrote:
>
>>Andyza wrote on 04 mrt 2009 in microsoft.public.inetserver.asp.general:
>>
>>> sUnixDate = "1235999914"
>>> sNewDate = DateAdd("s",sUnixDate,#1970/1/1#)
>>>
>>> sNewDate now contains the date according to the regional settings on
>>> the computer eg:
>>>
>>> '3/2/2009 1:18:34'
>>> or
>>> '2009/03/02 01:18:34'

>>
>>No, it does not.
>>
>>sNewDate contains the date/time,
>>independent of the regional settings.
>>
>>It does not contain the way it is transcribed into a string.

>
> True, but it doesn't answer the question.


At least it answers a conceptual mistake in the OP's thought.

>>> Is there a way to specify a format for the date that
>>> is independent of the Regional Settings on the computer?



> VBScript's FormatDate
> function can display a date in several formats, all of which refer to
> the computer's regional settings. AFAIK, there's no way to specify how
> you want the date to look independent of the regional settings.
>
> I suppose you could write your own function to do the necessary
> arithmetic on the date value and format it as you want.


And that isn't a way, Tim?

I think it is, it is the best way for my and the OP's purpose

I never use FormatDate() but build the function myself.


sUnixDate = "1235999914"
sNewDate = DateAdd("s",sUnixDate,#1970/1/1#)


timeDutchString = day(sNewDate)&"-"&month(sNewDate)&"-"&year(sNewDate)&_
" "&minute(sNewDate)&":"&second(sNewDate)







--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Unix timestamp to Readable Date/time kaklis@gmail.com Python 1 07-22-2010 01:01 PM
Convert date/time to unix timestamp? Phillip B Oldham Python 2 02-10-2009 01:25 PM
why java timestamp format is different form php or normal unix format islamelnaggar Java 4 02-24-2008 03:07 PM
why java timestamp format is different form php or normal unix format islamelnaggar Java 0 02-24-2008 02:35 PM
how to convert date to unix timestamp Fibre Optic C++ 1 02-23-2007 12:30 PM



Advertisments