The Forum has been Updated
The code has been upgraded to the latest .NET core version. Please check instructions in the Community Announcements about migrating your account.
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.
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.
Sist redigert av
Postet den
Hmm... Not elegant, but it works...
Code:
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"
Postet den
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.
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.
Sist redigert av
Postet den
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
Doug G
======
Computer history and help at www.dougscode.com
Postet den
Here you go, to get GMT:
Code:
' ## 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 />"
Sist redigert av
Postet den
DateTime.UtcNow.AddMinutes(20).ToString("yyyy-MM-ddTHH:mm:ssZ")
should work fine in .Net what exactly isn't working?
should work fine in .Net what exactly isn't working?
Postet den
Thanks CareFree!
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.
what exactly isn't working?
There's a nut loose somewhere between my chair and the monitor.
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.
Sist redigert av
Postet den
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
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.
What exactly are you trying to do?
the code below will give you the correct UTC time for your server
Code:
<%
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>
Postet den
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.
Email Member
Message Member
Post Moderation
Filopplasting
If you're having problems uploading, try choosing a smaller image.
Forhåndsvis post
Send Topic
Loading...