Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple working with dates

Status
Not open for further replies.

mrbusy

Technical User
Dec 10, 2003
118
I would like to do some basic stuff with ASP but I'm not exactly sure the best way to get to what I want.

I have a common homepage for all users with links and other useful data on it. I would like to add timezones at the top of the page so people can quickly find out what the time is in LA or Boston at a glace. This page is served from our Exchange server running IIS.

I've done a little with ASP before, for example displaying the current date and time at the top of the page, but I don't actually manipulate that data. I almost managed get the effect I wanted by using
EST <%=hour(now)-5%>:<%=minute(now)%>
but unforuntaely this drops leading zeros so three minutes past four would be displayed 16:3, which isn't very good.

Can anyone tell me, is there any easy way for me to take the current server time, add or subtract a specific number of hours, then display it in a meaninful format?

Many thanks in advance.
 
I'd suggest using the .NET framework rather than old VB functions. Something like the following should work:
Code:
lblHour.Text = System.DateTime.Now.AddHours(3).ToShortTimeString


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Additionally, what you want to do is a built-in feature of ASP.NET. Check out the date format strings:


i.e. You could do either:

EST <%=DateTime.Now.AddHours( -5 ).ToShortTimeString()%>

or

EST <%=DateTime.Now.AddHours( -5 ).ToString( "t" )%>

or use some other custom format to print it out however you'd like (see link for more).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top