Code2care : TechZone Apps & Tutorials

How to get UTC (GMT) using javascript



To get Universal Time (UTC) or Greenwich Mean Time (GMT) timestamp using javascript we need to use toUTCString() function on Date variable.

Example :


<!DOCTYPE html>
<html>
<head>
<script>
function getUTC() {

  //Get timestamp in locale
  var tDate = new Date();

  //Convert timestamp in GMT/UTC format
  var utcDate = tDate.toUTCString();
  

  document.getElementById("utc").innerHTML = utcDate;
  console.log(utcDate);
}
</script>
</head>


<body onload="getUTC()">

<div id="utc"></div>

</body>
</html>





Output :




Note : There is no difference between GMT and UTC time.











Top




Posts related to javascript.


1. Top 15 Programming Languages to learn 2014-2015

2. How to detect Browser and Operating System Name and Version using javaScript

3. How to make jsfiddle bootstrap ready

4. Detect if Cookies are enabled using javascript

5. How to get UTC (GMT) using javascript

6. Add Animated Scrolling to Html Page Title Script

7. Loading previous page using html button using javascript

8. Get Device Screen Width and Height using javaScript

9. Digital clock example using javaScript with Source code

    more...






Popular tags
android
x 175
eclipse
x 29
notepadplusplus
x 20
macosx
x 14
sharepoint
x 14
html
x 14
mac
x 13
androidstudio
x 11




1000+ C Programs     PHP Tutorial     JSON Tutorial     Swift Tutorial     India Pinocdes     About Us     Privacy Policy


Code2care © 2012-17