Click here to Skip to main content
15,899,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

How can I format the current+24 hour Date and Time to look like this:
Mon, 24-May-2010 21:23:04 GMT

Thanks
Posted
Updated 24-May-10 12:48pm
v4

It would help if you old us what language. The to string method on the date time takes format strings. http://www.codeproject.com/KB/cs/String2DateTime.aspx
 
Share this answer
 
String.Format("{0:r}", DateTime.Now);

(DateTime.Now).ToString("{0:r}");
 
Share this answer
 
Comments
guyanese4life2 24-May-10 15:35pm    
.NET
William Winner 24-May-10 19:03pm    
Reason for my vote of 2
your String.Format works though it will only return GMT if in that time zone.

(DateTime.Now).ToString("{0,r}") returns "{0,r}" not a formatted time code.
guyanese4life2 22-Jun-10 9:30am    
Lol, if it works don't you think it deserves a little more than a 2?
see here[^] for a list of formats that you can use.

here are some options:

VB
DateTime.UtcNow.ToString("r")
'equals Mon, 24 May 2010 22:56:46 GMT

'If you want to add the hyphens try

DateTime.UtcNow.ToString("ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'")
'equals Mon, 24-May-2010 22:56:46 GMT


you definitely want UtcNow though because that will convert it to coordinated universal time which "in casual use, when fractions of a second are not important, Greenwich Mean Time (GMT) can be considered equivalent to UTC or UT1" from http://en.wikipedia.org/wiki/Coordinated_Universal_Time[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900