Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 4th, 2005, 02:40 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Formatting the Client Time

I am able to access the time on the client's machine clock by using the javascript getTime(); method. However, I'm going crazy trying to convert that value into a human-friendly format, like 1:37. Right now I get the milliseconds since Jan 1st 1970 (something like "1107542083053").

FYI, I am currently able to display the value from the client in a label through the Page_Load event. Getting the value is not an issue.

Thanks in advance for your comments.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old February 4th, 2005, 02:56 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I have a funtion that may help. I used this function to default drop down lists to the current time. You may be able to use it and just concantinate the time portions however you like. Hope this helps, let me know.

function formatDateTime()
{
   var currdate = new Date();
   var hourval = currdate.getHours();
   var minval = currdate.getMinutes();
   var AMPM = 0; //AM

   if (hourval >= 12)
   {
      AMPM = 1; //PM
   }

   if (hourval > 12)
   {
      hourval -=12;
   }

   document.frmCallBox.hour.selectedIndex = hourval - 1;
   document.frmCallBox.min.selectedIndex = minval;
   document.frmCallBox.ampm.selectedIndex = AMPM;
} //End formatDateTime()
 
Old February 4th, 2005, 03:00 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks J-

Actually, getting the current time this way was something I looked at previously, but I need to do a calculation with it. I'm adding 30 minutes (1,800,000 milliseconds) to it and then displaying that time to the user.

Sorry about not mentioning that earlier.

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old February 4th, 2005, 03:06 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Not a problem.

Why not use the code and add 30 minutes to the minVal variable?

Something like:
var minval = currdate.getMinutes() + 30;

Jim
 
Old February 5th, 2005, 12:41 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jim-

Thanks for the insight. I took your idea and added some dressing around it.
Code:
function getExpTime(){
    var d = new Date();
    var curHour = d.getHours();
    var curMinute = d.getMinutes() + 30;
    if(curMinute >= 60){
        curHour += 1;
        curMinute -= 60;
    }
    if(curHour > 12){
        curHour = curHour - 12;
    }
    if(curMinute < 10){
        curMinute = "0" + curMinute;
    }
    var exp = curHour + ":" + curMinute;
    return exp;
}
Works like a charm. Thanks!

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old February 6th, 2005, 01:49 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Glad I can help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Time Output braunj ASP.NET 2.0 Basics 0 October 6th, 2008 10:27 PM
Formatting and creating date and Time Audioicon ASP.NET 3.5 Basics 3 September 22nd, 2008 07:58 PM
formatting date time Adam H-W Classic ASP Basics 4 September 29th, 2004 03:35 AM
Formatting a Field Containing a Time to AM/PM taleriana XSLT 2 March 16th, 2004 11:10 PM
Time: formatting from seconds to serial comets Classic ASP Basics 2 July 22nd, 2003 04:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.