I want to show a current time whatever the system time is.I am developing the hybrid mobile application in offline. I need a correct time of current if I changed the device time means it will show the current time only is there any possibility for that.In the new date is giving the what is the system date.If I change the system date javascript show that date only.
Asked
Active
Viewed 804 times
1
-
I don't think this is possible. – str Sep 15 '16 at 09:38
2 Answers
0
If no argument is provided in Date() constructor function, a JavaScript Date object is created according to the system time settings. The MDN Documentation for Date object says:
If no arguments are provided, the constructor creates a JavaScript Date object for the current date and time according to system settings.
Syntax for getting JavaScript Date
new Date();
new Date(value);
new Date(dateString);
new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);
You can follow this approach to show the correct time irrespective of the system time:
- When the app loads for the first time, make a call to your server to get current timestamp,
- compare the server timestamp with the system timestamp, and store the difference in a variable (let's call it offset).
- Write a custom function which returns the correct time by adding/subtracting the offset from the system time.

Aaditya Sharma
- 3,330
- 3
- 24
- 36
-
This approach won't be useful. First, the `date` object already contains the offset from UTC, and second, the system time may be changed while being offline. – str Sep 15 '16 at 09:38
-
i need a offline mode.no server interaction.Is it possible or not?.To getting the exact time – Kalai Prakash Sep 15 '16 at 09:38
-
This is an interesting problem @KalaiPrakash. I'm digging more into it. – Aaditya Sharma Sep 15 '16 at 09:41
-
Android mobile have the setting option use network provider time for automatic like that anything will be there in javascript or plugins in phonegap? – Kalai Prakash Sep 15 '16 at 09:44
-1
You can use new Date().getTime();
For more information click here

Community
- 1
- 1

Menaka Kariyawasam
- 618
- 7
- 28
-
no i need current time.you way is showing the system time. example if i change the system time 2:00 means it will returns 2;00 only.but what actually i need is current time that means 2:37 ist – Kalai Prakash Sep 15 '16 at 09:18