?
Solved

Javascript document.write problem with date()

Posted on 2008-06-11
5
Medium Priority
?
452 Views
Last Modified: 2008-06-11
Hi guys hope u r well and can assist.

I have the following 1 liner javascript file.....

document.write(Date());

The output is the following..

Wed Jun 11 2008 17:56:28 GMT+1000 (AUS Eastern Standard Time)

Is there any way to modify the document.write(Date());
so that I only get the following?

Wednesday June 11, 2008 17:56:28

So, the
GMT+1000 (AUS Eastern Standard Time) - is removed.
The day is expanded to its full name
The month is also expanded to its full name.

Would really appreciate your help.
Thank you.
0
Comment
Question by:Simon336697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
russhuntington earned 2000 total points
ID: 21757871
There a few download-able formatting functions out there, but you could just write your own as you exactly what you want. Try this:
<script type="text/javascript">
 
var d = new Date();
formatDate(d)
 
function formatDate(date)
{
var days = new Array();
days[0] = "Sunday";
days[1] = "Monday";
days[2] = "Tuesday";
days[3] = "Wednesday";
days[4] = "Thursday";
days[5] = "Friday";
days[6] = "Saturday";
 
var months = new Array();
months[0] = "January";
months[1] = "February";
months[2] = "March";
months[3] = "April";
months[4] = "May";
months[5] = "June";
months[6] = "July";
months[7] = "August";
months[8] = "September";
months[9] = "October";
months[10] = "November";
months[11] = "December";
 
var dateString = days[date.getDay()] + " " + months[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
document.write (dateString);
}
 
</script>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 21757930
HI russhuntington,

Mate thank you so much for that..
That is exactly what I was looking for.
Really appreciate it.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 21759173
FYI:

  The syntax used above is very verbose.  Here are more concise ways to initialize
the two arrays to the same values as shown above:

var days = 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday'.split( ',' );

var months = 'January,February,March,April,May,June,July,August,September,October,November,December'.split( ',' );
0
 
LVL 2

Expert Comment

by:russhuntington
ID: 21760912
Good point, although I think would go for the following instead of the split method.

var days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 21761458
yeah, except that is so much more typing... :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question