home *** CD-ROM | disk | FTP | other *** search
/ 207.233.110.77 / 207.233.110.77.tar / 207.233.110.77 / web31 / Section_78401 / Students / Barzola_Henry / tutorial.10 / case1 / datetime.js next >
Text File  |  2011-11-30  |  1KB  |  37 lines

  1. /*
  2.    New Perspectives on HTML and XHTML 5th Edition
  3.    Tutorial 10
  4.    Case Problem 1
  5.  
  6.    Function List:
  7.    showDate
  8.       Used to return a text string containing the current date and time.
  9.    getMap
  10.       Used to the determine the current sky map number to display with the online planisphere
  11.  
  12. */
  13.  
  14.  
  15. function showDateTime() {
  16.    var thisDate = new Date();
  17.    var thisWDay=thisDate.getDay();
  18.    var thisDay=thisDate.getDate();
  19.    var thisMonth=thisDate.getMonth();
  20.    var thisYear=thisDate.getFullYear();
  21.    var mName = new Array("January", "February", "March", "April", "May", 
  22.        "June", "July", "August", "September", "October","November", "December");
  23.    var hours=thisDate.getHours();
  24.    var minutes=thisDate.getMinutes();
  25.    ampm = hours >=12 ? " pm" : " am";
  26.    hours = hours > 12 ? hours-12 : hours;
  27.    minutes = minutes < 10 ? "0"+minutes : minutes;
  28.    return mName[thisMonth]+" "+thisDay+", "+thisYear + ", " + hours + ":" + minutes + ampm;
  29. }
  30.  
  31. function getMap() {
  32.    thisTime = new Date();
  33.    hour = thisTime.getHours();
  34.    month = thisTime.getMonth();
  35.    mapNumber = (month*2+hour)%24;
  36.    return mapNumber;
  37. }