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
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date(); alert(myDate.toUTCString());">toUTCString</button> </body> </html>
</source>
Convert time to a UTC Date
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date(); alert(Date.UTC(myDate));">UTC</button> </body> </html>
</source>
Get UTC Date
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date(); alert(myDate.getUTCDate());"> Date: get UTC Date </button> </body> </html>
</source>
Get UTC Day
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date();
alert(myDate.getUTCDay());">Date: get UTC Day</button>
</body> </html>
</source>
Get UTC Hours
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date();
alert(myDate.getUTCHours());">Date: get UTC Hours</button>
</body> </html>
</source>
Get UTC Milliseconds
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date();
alert(myDate.getUTCMilliseconds());">Date: get UTC Milliseconds</button>
</body> </html>
</source>
Get UTC Minutes
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date(); alert(myDate.getUTCMinutes());">Date: getUTCMinutes</button> </body> </html>
</source>
Get UTC Month
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date();
alert(myDate.getUTCMonth());">Date: GETUTCMONTH</button>
</body> </html>
</source>
Get UTC Seconds
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date(); alert(myDate.getUTCSeconds());">Date: getUTCSeconds</button> </body> </html>
</source>
Set UTC Date
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date();
myDate.setUTCDate(20); alert(myDate);">Date: set UTC Date</button>
</body> </html>
</source>
Set UTC Full Year
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date();
myDate.setUTCFullYear(2030); alert(myDate);">Date: set UTC Full Year</button>
</body> </html>
</source>
Set UTC Hours
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date();
myDate.setUTCHours(11); alert(myDate);"> Date: set UTC Hours</button>
</body> </html>
</source>
Set UTC Milliseconds
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date();
myDate.setUTCMilliseconds(20); alert(myDate);">Date: set UTC Milliseconds</button>
</body> </html>
</source>
Set UTC Minutes
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date();
myDate.setUTCMinutes(22); alert(myDate);">
Date: set UTC Minutes </button> </body> </html>
</source>
Set UTC Month
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date();
myDate.setUTCMonth(2); alert(myDate);"> Date: set UTC Month
</button> </body> </html>
</source>
Set UTC Seconds
<source lang="html4strict">
<html> <body> <button onclick="var myDate = new Date();
myDate.setUTCSeconds(12); alert(myDate);">Date: set UTC Seconds</button>
</body> </html>
</source>