Solved

Format date time in html page

Posted on 2014-09-08
10
179 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now