Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Getting server time in ISO 8601 Format...

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!
Before posting, make sure you have read this topic!

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
   

T O P I C    R E V I E W
bobby131313 Posted - 13 February 2012 : 11:25:35
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.
8   L A T E S T    R E P L I E S    (Newest First)
bobby131313 Posted - 15 February 2012 : 10:25:37
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.
HuwR Posted - 15 February 2012 : 10:11:50
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.
bobby131313 Posted - 15 February 2012 : 09:43:12
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.
HuwR Posted - 15 February 2012 : 03:05:37
DateTime.UtcNow.AddMinutes(20).ToString("yyyy-MM-ddTHH:mm:ssZ")

should work fine in .Net what exactly isn't working?
Carefree Posted - 15 February 2012 : 01:53:50
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 />"
Doug G Posted - 14 February 2012 : 21:36:13
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.
bobby131313 Posted - 14 February 2012 : 20:34:13
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.
bobby131313 Posted - 13 February 2012 : 12:55:02
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"


Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000 Version 3.4.07