Setting linux time properly (UTC) - linux

I have problems with the time settings on my linux server. The timezone is set to UTC, the locale settings are the following: (locale -a)
C
C.UTF-8
en_GB.utf8
POSIX
date command gives me
Wed Jul 26 09:39:42 UTC 2017
but the correct time is 10:39
On my desktop I have the same locale settings and utc timezone and it gives me the correct time.
Could someone explain what's wrong with the server and what should be changed, please?
Thanks in advance.

Related

cross platform api or bin file to validate daylight savings time in a system

I want to get the status of daylight savings time in cross platforms as in the command timedatectl as active/not active. Since I am trying it with cross platforms I don't want to use timedatectl.
So my questions are:
When I use timedatectl status command in my system, it is not showing the DST Status. I don't know why. Can anybody explain this?
** My System output **
$ timedatectl status
Local time: Tue 2021-06-29 16:26:16 IST
Universal time: Tue 2021-06-29 10:56:16 UTC
RTC time: Tue 2021-06-29 10:56:16
Time zone: Asia/Kolkata (IST, +0530)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
It is not showing DST active : a (or) n/a status. I want know why?
Is there any default API or bin files similar to timedatectl to do the job of validating the DST is active/not status in the system (cross platforms)?

Node.js Date does not consider DST (daylight saving time)

I'm living in Vancouver, west coast of North America, Canada. The original timezone here is PST (pacific standard time, UTC - 8h), but it's now PDT (pacific daylight time, UTC - 7h) since the daylight saving time has started.
The problem is that Node.js uses the original non-DST time, while Ubuntu returns DST.
In the following, both should be 21:44.
$ echo `date` , `node -e "console.log(new Date().toString())"`
Mon May 25 21:44:57 DST 2020 , Mon May 25 2020 20:44:57 GMT-0800 (GMT-08:00)
Why does this happen? How to let Node.js recognize DST?
I use Noce.js v12.16.3 on Ubuntu 18.04.4 as WSL on Windows 10. (Node.js v12.16.3 for Windows works correctly.) TZ env is not set.
UPDATE I don't want to install external libraries.
A more accurate library would be moment.js. You can set the time to recognize DST like this:
moment(timestamp).tz(timezone).isDST()
Here is an example:
moment(1451624400000).tz('America/New_York').isDST();
You can read more about recognized timestamps and timezones in the documentation on the website that I linked above.
My test shows that node does honor daylight saving time:
$ date; node -e "console.log(new Date().toString())";
Fri Jul 17 23:13:32 EDT 2020
Fri Jul 17 2020 23:13:32 GMT-0400 (Eastern Daylight Time)
$ date --date='Fri Jul 17 2020 23:13:32 GMT-0400'
Fri Jul 17 23:13:32 EDT 2020
$ node -v
v10.21.0
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal

timezone change in redhat

I tried to change time zone in redhat 7 from UTC to Asia/Kuala_Lumpur using command:
#timedatectl set-timezone Asia/Kuala_Lumpur
but it shows as below:
[root#mykultestrhel04t ~]# timedatectl
Local time: Thu 2019-08-22 06:41:03 UTC
Universal time: Thu 2019-08-22 06:41:03 UTC
RTC time: Thu 2019-08-22 06:41:03
Time zone: Asia/Kuala_Lumpur (UTC, +0000)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
I want the result to be instead as below:
Time zone: Asia/Kuala_Lumpur (+08, +0800)
How can I change it to (+08, +0800)
Can anyone help?
You need to change the TZ environment variable. MY is the timezone setting for Malaysian peninsular.
export TZ=MY
You would normally add this command in your /etc/profile file. /etc/profile is the system-wide start-up script which will apply to all system users.
Note you can check from the shell your correct timezone setting using the tzselect shell command. It comes handy when you want to know what time it is in other countries, or if you just wonder what
timezones exist.

Servers with same timezone but different time

I have 3 servers, 2 on AWS and one on Digital Ocean, and the timezone for all is set to CDT. But when I check the current time on all 3 by using the date command via command line, none of them matches.
Server1: Wed Jun 12 23:36:01 CDT 2019
Server2: Wed Jun 12 23:45:51 CDT 2019
Server3: Wed Jun 12 23:38:39 CDT 2019
Could anyone please suggest what needs to be done here? Thanks.
Since you have not explicitly said that you have ntp running on them, you'll need to install that. Once that is installed and set up properly, you should show the same exact time on all of them.

Date.now() (in node.js) is targeting the universal time in ubuntu

I'm using ubuntu for serving my website and I've used Date.now() a couple of times to get the current date. I live in Beirut (which is around 12:40 PM right now) and Date.now() is logging minus 2 hours (10:40 PM).
I changed the localtime of ubuntu by doing this command:
sudo dpkg-reconfigure tzdata
It's printing this:
Local time is now: Tue Feb 27 12:40:59 EET 2018.
Universal Time is now: Tue Feb 27 10:40:59 UTC 2018.
But it still doesn't work.
Basically, I want Date.now() to target the local time instead of universal one...
Date.now() returns the milliseconds elapsed since the UNIX epoch, and has no concept of timezone whatsoever.

Resources