?
Solved

Format date time in html page

Posted on 2014-09-08
10
Medium Priority
?
197 Views
Last Modified: 2014-09-27
Hi There,

The below code displayed current system date and time:

My question is how can I remove the time and GMT details from the date returned and display like

Monday 08 September 2014

<html>
 <head>
 <script type="text/javascript">
 document.getElementById('TD_ROW_ID').innerHTML = Date();
 </script>
 </head>
 <body>
 <table>
 <tr><td id="TD_ROW_ID"></td></tr>
 </table>
 </body>
 </html>

Open in new window

0
Comment
Question by:motolanix1
[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
10 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40309865
This should be what you are looking for:

var d = new Date();
document.getElementById("demo").innerHTML = d.toDateString();

Here is a full tutorial on how to work with dates:
http://www.w3schools.com/js/js_dates.asp
0
 

Accepted Solution

by:
motolanix1 earned 0 total points
ID: 40309908
It currently displays GMT+0100 (GMT Daylight Time at the end

How do I remove this?
0
 

Author Comment

by:motolanix1
ID: 40309919
Sorry I mean it displays Mon Sep 08 2014

How can it display Monday September 08 2014 or Monday Sep 08 2014
0
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 
LVL 29

Assisted Solution

by:becraig
becraig earned 1200 total points
ID: 40309967
Here you go:
<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>var date = new Date();
var options = {
    weekday: "long", year: "numeric", month: "long",
    day: "numeric", hour: "2-digit", minute: "2-digit"
};

document.write(date.toLocaleTimeString("en-us", options));
</script>

</body>
</html>

Open in new window

0
 

Author Comment

by:motolanix1
ID: 40309979
where is the id "demo" referenced in the code?

I don't see it?
0
 
LVL 29

Expert Comment

by:becraig
ID: 40309988
It's not referenced anywhere I should have stripped it out.

The only parts you need are:

<script>
var options = {
    weekday: "long", year: "numeric", month: "long",
    day: "numeric"
};
var d = new Date();
document.getElementById("demo").innerHTML = d.toLocaleDateString("en-us", options);
</script>

Open in new window



Edited (Removed the time)
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 300 total points
ID: 40310012
test page : http://jsfiddle.net/b9qoosot/

window.onload = function() {
    var d = new Date();
    var days = [ "Sunday", "Monday" ]; // and so on
    var months = [ "January", "February", "March","April","May","June", "July","August","September", "October", "November","December"];
    // Monday 08 September 2014
    document.getElementById('TD_ROW_ID').innerHTML =  days[ d.getDay() ] + " " + d.getDate() + " " + months[ d.getMonth() ] + " " + d.getYear();
}

Open in new window

0
 
LVL 29

Assisted Solution

by:becraig
becraig earned 1200 total points
ID: 40310026
<html>
 <head>
<script>
var options = {
    weekday: "long", year: "numeric", month: "long",
    day: "numeric"
};
var d = new Date();
document.getElementById("TD_ROW_ID").innerHTML = d.toLocaleDateString("en-us", options);
</script>
 </head>
 <body>
 <table>
 <tr><td id="TD_ROW_ID"></td></tr>
 </table>
 </body>
 </html>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 40311643
@becraig

toLocaleDateString("en-us", options);

is very cool, just note that the options are not supported by IE10 and lower and Safari.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

Also be aware that w3schools is considered to be a very poor resource

Lastly note that you need to wrap your setting of innerHTML in a window.onload or move the script to after when the cell is defined
0
 

Author Closing Comment

by:motolanix1
ID: 40347437
Solution was simple and easy to understand.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

752 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