Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Getting server time in ISO 8601 Format...
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bobby131313
Senior Member

USA
1163 Posts

Posted - 13 February 2012 :  11:25:35  Show Profile  Visit bobby131313's Homepage  Reply with Quote
How can I do that?

YYYY-MM-DDTHH:MM:SS.SSSZ (e.g., 2004-08-04T19:09:02.768Z)

Everything I Google is trying to get to the opposite... end user friendly.

TIA.

Switch the order of your title tags

Edited by - bobby131313 on 13 February 2012 11:26:25

bobby131313
Senior Member

USA
1163 Posts

Posted - 13 February 2012 :  12:55:02  Show Profile  Visit bobby131313's Homepage  Reply with Quote
Hmm... Not elegant, but it works...


intYear		= Year(Now)
intMonth	= Month(Now)
	If intMonth < 10 Then intMonth = "0" & intMonth
intDay		= Day(Now)
	If intDay < 10 Then intDay = "0" & intDay
intHour		= Hour(Now)
	If intHour < 10 Then intHour = "0" & intHour
intMinute	= Minute(Now)
	If intMinute < 10 Then intMinute = "0" & intMinute
intSecond	= Second(Now)
	If intSecond < 10 Then intSecond = "0" & intSecond

strTimePadding = intYear & "-" & intMonth & "-" & intDay & "T" & intHour & ":" & intMinute & ":" & intSecond & ".000Z"


Switch the order of your title tags
Go to Top of Page

bobby131313
Senior Member

USA
1163 Posts

Posted - 14 February 2012 :  20:34:13  Show Profile  Visit bobby131313's Homepage  Reply with Quote
bleh.... this is working but sloppy. What I really need is GMT time, then be able add time to it if I want, and get it in the format above. I belive I could use asp.net too, if anyone has any ideas...

I've come across some code like this...

DateTime.UtcNow.AddMinutes(20).ToString("yyyy-MM-ddTHH:mm:ssZ")

while Googling, but I'm kinda lost and can't get it working.

Switch the order of your title tags

Edited by - bobby131313 on 14 February 2012 20:38:26
Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 14 February 2012 :  21:36:13  Show Profile  Reply with Quote
Is this windows? If yes, I have no idea. If linux, review man date which you can use to get just about any date format you want to a string.

======
Doug G
======
Computer history and help at www.dougscode.com
Go to Top of Page

Carefree
Advanced Member

Philippines
4207 Posts

Posted - 15 February 2012 :  01:53:50  Show Profile  Reply with Quote
Here you go, to get GMT:


'	##	Display GMT
Function Twodigits(strInfo)
	If len(strInfo) > 1 Then 
		Twodigits = strInfo 
	Else 
		Twodigits = "0" & strInfo
	End If
End Function
Dim dtmDateValue, dtmAdjusted, objShell, lngBiasKey, lngBias
dtmDateValue = Now()
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" & "TimeZoneInformation\ActiveTimeBias")
If (UCase(TypeName(lngBiasKey)) = "LONG") Then
	lngBias = lngBiasKey
ElseIf (UCase(TypeName(lngBiasKey)) = "VARIANT()") Then
	lngBias = 0
	For k = 0 To UBound(lngBiasKey)
		lngBias = lngBias + (lngBiasKey(k) * 256^k)
	Next
End If
dtmAdjusted = DateAdd("n", lngBias, dtmDateValue)
dts = year(dtmAdjusted) & Twodigits(Month(dtmAdjusted)) & Twodigits(Day(dtmAdjusted)) & Twodigits(Hour(dtmAdjusted)) & Twodigits(Minute(dtmAdjusted)) & Twodigits(Second(dtmAdjusted)) & ""
Response.Write	"GMT is now:  " & dtmAdjusted & "<BR />GMT String=" & dts & "<br />"
Response.Write	"Desired Format: " & year(dtmAdjusted) & "-" & Twodigits(Month(dtmAdjusted)) & "-" & Twodigits(Day(dtmAdjusted)) & " " & Twodigits(Hour(dtmAdjusted)) & ":" & Twodigits(Minute(dtmAdjusted)) & ":" & Twodigits(Second(dtmAdjusted)) & ".000Z<br />"
Response.Write	"Server Time: " & dtmDateValue & "<br />"

Edited by - Carefree on 15 February 2012 02:14:26
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 15 February 2012 :  03:05:37  Show Profile  Visit HuwR's Homepage  Reply with Quote
DateTime.UtcNow.AddMinutes(20).ToString("yyyy-MM-ddTHH:mm:ssZ")

should work fine in .Net what exactly isn't working?

MVC .net dev/test site | MVC .net running on Raspberry Pi
Go to Top of Page

bobby131313
Senior Member

USA
1163 Posts

Posted - 15 February 2012 :  09:43:12  Show Profile  Visit bobby131313's Homepage  Reply with Quote
Thanks CareFree!

quote:
what exactly isn't working?


There's a nut loose somewhere between my chair and the monitor. The problem is I know absolutely zero about ASP.Net. That type code is posted everywhere on the net, the reply is always "Thanks worked like a charm!" or something similar. But I have no idea how to use it (like set the value in a variable), typical asp I'm used to doesn't seem to work. How do I use that code to set the resulting string in a variable? Does the file ext have to be .aspx? My CP does say that ASP.Net version 2 is installed. This code would be awesome to get working because I want different padding on different pages and this would be very easy to change.


Carefree, your code gets the correct GMT time great, but I *think* I'm going to have my the same original problem. I need to be able to add an amount of time to it, without having to deal with it flipping past midnight and changing the day... or even the month and year for that matter.

Switch the order of your title tags

Edited by - bobby131313 on 15 February 2012 10:04:59
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 15 February 2012 :  10:11:50  Show Profile  Visit HuwR's Homepage  Reply with Quote
asp.net is very different to classic ASP, you can't use both together (well not easily anyway) the biggest problem with classic asp is that it doesn't reaally know anything about datetime other than the one the system uses, so you either have to interrogate the registry as in carefrees example (really not a good idea to allow websites access to the registry) or there are functions you can use in javascript which may help.

What exactly are you trying to do?

the code below will give you the correct UTC time for your server

<%
response.write currentUTC()
%>

<script language=jscript runat=server>
function currentUTC(){
var d, s;
d = new Date();
s = "Server current UTC time is: ";
s += d.toUTCString();
return(s);
}
</script>

you could capture this in a hidden formfield and then use normal string parsing to get the date into the format you want and/or workout the timezone diff etc.

MVC .net dev/test site | MVC .net running on Raspberry Pi
Go to Top of Page

bobby131313
Senior Member

USA
1163 Posts

Posted - 15 February 2012 :  10:25:37  Show Profile  Visit bobby131313's Homepage  Reply with Quote
quote:
What exactly are you trying to do?


I'm working with the eBay API and caching the returned results. This works great except when I use the "Auctions ending Soonest" sort. Since I'm caching, I get a ton of people clicking on links to auctions that are over. Now eBay lets me specify in the call a time (in the format above) that auctions must end after based on GMT time. So if I send the timestamp 4 hours in the future, then cache for 3 1/2 hours, that gives the user 30 minutes to be on the page clicking links before there's any chance of clicking on an ended listing.

Switch the order of your title tags
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.13 seconds. Powered By: Snitz Forums 2000 Version 3.4.07