Commonly Used JavaScript Date Objects

2. The Date() Object

2.1. An example of using the Date() object for a programming problem

San Francisco, California is -16 hours from our time zone (current time minus 16 hours). Create a program that gives the current time of San Francisco. The code below gives a solution for this problem. Take note that the time zone in the output is based on the time zone of the computer where the code is run and it is not the time zone of San Francisco per se. This is because the only basis for the time of San Francisco is the time difference and the resulting computed value.


Sample user’s current time: Wed Jan 06 2021 11:15:43 GMT+0800 (China Standard Time) Sample Output: Tue Jan 05 2021 19:15:43 GMT+0800 (China Standard Time)