How to Convert a JavaScript Date to Time Stamp
JavaScript is a programming language you can use to create dynamic Web pages that feature interactive content such as forms and current time. The Date object contains information about the current month, day, year and time. Use methods of the Date object to include a time stamp on your page.
Instructions
-
-
1
Open your Web page using a text or HTML editor.
-
2
Type a JavaScript function that will output the current time:
<script>
function insertTime(){
TS = new Date();
document.write(TS.getHours()+":"+TS.getMinutes());
}
</script>
A Date object is created and then used to get the current hour and minutes.
-
-
3
Type your "insertTime()" function inside script tags wherever you want to place your time stamp:
<p> Time: <script>insertTime()</script></p>
-
4
Save the file. Display it in a Web browser to view the results.
-
1
Resources
- Photo Credit Jupiterimages/Photos.com/Getty Images