Solved

Format date time in html page

Posted on 2014-09-08
10
192 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
Industry Leaders: 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!

 
LVL 29

Assisted Solution

by:becraig
becraig earned 400 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 100 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 400 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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…

707 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