
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Set Current Time to Another Time in JavaScript
You cannot do this with JavaScript since it takes the system time which displays the current date with Date object. However, you can change the current date by changing the timezone as in the following code −
Example
<!DOCTYPE html> <html> <body> <script> var date, offset, nd; date = new Date(); document.write("Current: "+date); utc = date.getTime() + (date.getTimezoneOffset() * 60000); // Singapore is GMT+8 offset = 8; nd = new Date(utc + (3600000*offset)); document.write("<br>Singapore Time: "+nd.toLocaleString()); </script> </body> </html>
Output
Advertisements