JavaScript DHTML/Date Time/UTC Date
Содержание
- 1 Convert Date to UTC String
- 2 Convert time to a UTC Date
- 3 Get UTC Date
- 4 Get UTC Day
- 5 Get UTC Hours
- 6 Get UTC Milliseconds
- 7 Get UTC Minutes
- 8 Get UTC Month
- 9 Get UTC Seconds
- 10 Set UTC Date
- 11 Set UTC Full Year
- 12 Set UTC Hours
- 13 Set UTC Milliseconds
- 14 Set UTC Minutes
- 15 Set UTC Month
- 16 Set UTC Seconds
Convert Date to UTC String
<html>
<body>
<button onclick="var myDate = new Date(); alert(myDate.toUTCString());">toUTCString</button>
</body>
</html>
Convert time to a UTC Date
<html>
<body>
<button onclick="var myDate = new Date(); alert(Date.UTC(myDate));">UTC</button>
</body>
</html>
Get UTC Date
<html>
<body>
<button onclick="var myDate = new Date(); alert(myDate.getUTCDate());">
Date: get UTC Date
</button>
</body>
</html>
Get UTC Day
<html>
<body>
<button onclick="var myDate = new Date();
alert(myDate.getUTCDay());">Date: get UTC Day</button>
</body>
</html>
Get UTC Hours
<html>
<body>
<button onclick="var myDate = new Date();
alert(myDate.getUTCHours());">Date: get UTC Hours</button>
</body>
</html>
Get UTC Milliseconds
<html>
<body>
<button onclick="var myDate = new Date();
alert(myDate.getUTCMilliseconds());">Date: get UTC Milliseconds</button>
</body>
</html>
Get UTC Minutes
<html>
<body>
<button onclick="var myDate = new Date();
alert(myDate.getUTCMinutes());">Date: getUTCMinutes</button>
</body>
</html>
Get UTC Month
<html>
<body>
<button onclick="var myDate = new Date();
alert(myDate.getUTCMonth());">Date: GETUTCMONTH</button>
</body>
</html>
Get UTC Seconds
<html>
<body>
<button onclick="var myDate = new Date();
alert(myDate.getUTCSeconds());">Date: getUTCSeconds</button>
</body>
</html>
Set UTC Date
<html>
<body>
<button onclick="var myDate = new Date();
myDate.setUTCDate(20);
alert(myDate);">Date: set UTC Date</button>
</body>
</html>
Set UTC Full Year
<html>
<body>
<button onclick="var myDate = new Date();
myDate.setUTCFullYear(2030);
alert(myDate);">Date: set UTC Full Year</button>
</body>
</html>
Set UTC Hours
<html>
<body>
<button onclick="var myDate = new Date();
myDate.setUTCHours(11);
alert(myDate);">
Date: set UTC Hours</button>
</body>
</html>
Set UTC Milliseconds
<html>
<body>
<button onclick="var myDate = new Date();
myDate.setUTCMilliseconds(20);
alert(myDate);">Date: set UTC Milliseconds</button>
</body>
</html>
Set UTC Minutes
<html>
<body>
<button onclick="var myDate = new Date();
myDate.setUTCMinutes(22);
alert(myDate);">
Date: set UTC Minutes
</button>
</body>
</html>
Set UTC Month
<html>
<body>
<button onclick="var myDate = new Date();
myDate.setUTCMonth(2);
alert(myDate);">
Date: set UTC Month
</button>
</body>
</html>
Set UTC Seconds
<html>
<body>
<button onclick="var myDate = new Date();
myDate.setUTCSeconds(12);
alert(myDate);">Date: set UTC Seconds</button>
</body>
</html>