Date & Time [Combine]

This is a discussion on "Date & Time [Combine]" within the JavaScript Forum section. This forum, and the thread "Date & Time [Combine] are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 5th, 2008, 22:53
Junior Member
Join Date: Mar 2008
Location: UK
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Post Date & Time [Combine]

Dear resident members,

I have two javascripts, one for date and one for time. The javascript in both these files calls the data locally from the user's pc.

I would like to know how to combine these two .js files into one.

The date .js file is written as follows:

Quote:
// Get today's current date.
var now = new Date();

// Array list of days.
var days = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');

// Array list of months.
var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','A ug','Sep','Oct','Nov','Dec');

// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

// Calculate four digit year.
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
}

// Join it all together
today = days[now.getDay()] + "&nbsp;" +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear())) ;

// Print out the data.
document.write("It is currently" + "&nbsp;" +today+ "&nbsp;");
The time .js file is written as follows:

Quote:
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()

var suffix = "am";
if (hours >= 12) {
suffix = "pm";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}

if (minutes < 10)
minutes = "0" + minutes

document.write(hours + ":" + minutes + " " + suffix)
Please can you explain how this would be done.

Many thanks.
Reply With Quote

  #2 (permalink)  
Old Mar 6th, 2008, 01:23
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: Date & Time [Combine]

Combine them into something like this:

Code: Select all
 			 				// Get today's current date.
var now = new Date();

// Array list of days.
var days = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');

// Array list of months.
var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','A  ug','Sep','Oct','Nov','Dec');

// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

// Calculate four digit year.
function fourdigits(number)    {
    return (number < 1000) ? number + 1900 : number;
                                }

// Join it all together
today =  days[now.getDay()] + "&nbsp;" +
              months[now.getMonth()] + " " +
               date + ", " +
                (fourdigits(now.getYear())) ;

			 				var currentTime = new Date()
  var hours = currentTime.getHours()
  var minutes = currentTime.getMinutes()

  var suffix = "am";
  if (hours >= 12) {
  suffix = "pm";
  hours = hours - 12;
  }
  if (hours == 0) {
  hours = 12;
  }

  if (minutes < 10)
  minutes = "0" + minutes;

document.write("It is currently" + "&nbsp;" +today+ "&nbsp;");
  document.write(hours + ":" + minutes + " " + suffix);
Give that a shot, see if it works.
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
  #3 (permalink)  
Old Mar 12th, 2008, 00:56
Junior Member
Join Date: Mar 2008
Location: UK
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Date & Time [Combine]

Thank you very much, but why two document.write commands? Can't they both be incorporated into the one?
Reply With Quote
  #4 (permalink)  
Old Mar 12th, 2008, 01:22
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: Date & Time [Combine]

i guess they could. Don't know why i kept them seperated. hmmmm........

*goes deep in to thought*
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Date/Time Button selfAfflicted JavaScript Forum 2 Aug 8th, 2007 14:25
Can't open the date time picker yuenli JavaScript Forum 0 Jul 3rd, 2007 07:22
How to format date/time from input box ? kahpeng Classic ASP 1 Mar 27th, 2006 05:08
Creating Date & Time SweetLou Classic ASP 1 Jan 23rd, 2006 13:55
Server time and date script gribble JavaScript Forum 1 Aug 16th, 2005 09:53


All times are GMT. The time now is 01:09.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43