How do I set time and date from the Internet?Trying to set date on a Linux based machine from another...
Python 3 - simple temperature program
How does the reduce() method work in Java 8?
To kill a cuckoo
What is a common way to tell if an academic is "above average," or outstanding in their field? Is their h-index (Hirsh index) one of them?
Why aren't nationalizations in Russia described as socialist?
Is the book wrong about the Nyquist Sampling Criterion?
How to pass hash as password to ssh server
Why didn't this character get a funeral at the end of Avengers: Endgame?
Is there an age requirement to play in Adventurers League?
Constitutional limitation of criminalizing behavior in US law?
Copy previous line to current line from text file
Is there a word for food that's gone 'bad', but is still edible?
Why is my arithmetic with a long long int behaving this way?
What do I do if my advisor made a mistake?
Are the Night's Watch still required?
Is there precedent or are there procedures for a US president refusing to concede to an electoral defeat?
Why would a military not separate its forces into different branches?
How long would it take for people to notice a mass disappearance?
How should I tell my manager I'm not paying for an optional after work event I'm not going to?
Formatting Datetime.now()
What are the advantages of luxury car brands like Acura/Lexus over their sibling non-luxury brands Honda/Toyota?
Mug and wireframe entirely disappeared
Why do these characters still seem to be the same age after the events of Endgame?
Handling Null values (and equivalents) routinely in Python
How do I set time and date from the Internet?
Trying to set date on a Linux based machine from another machineTrying to set date on a Linux based machine from another machineHow to force the time and date settings to refresh from the internet?What else apart from /etc/localtime and $TZ affects `date`?Automatically synchronization between system time and hardware clock timeHow to set time in nanoseconds?Getting the date from a ssh clienthow does the gnu coreutils `date` work?how to set the date & time PermanentlyChrony client do not change system and hardware dateSet date on embedded linux with limited busybox (no ntp)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
How do I retrieve the date from the Internet and set my computer's clock, from the command line?
command-line date remote clock
|
show 3 more comments
How do I retrieve the date from the Internet and set my computer's clock, from the command line?
command-line date remote clock
2
I do not understand downvotes. Simple questions are what make a community powerful. For example see this
– Mohsen
Jun 12 '13 at 6:35
3
When I hover above a question's down arrow with my mouse I see: "This question does not show any research effort; it is unclear or not useful". I would be tempted to downvote your question based on the first (no indication of what you found), the second (no indication on what specific platform you are working on, and why this has to be commandline (instead of the usual time daemon)) and the third (most *nix users will have some time daemon installed by default).
– Anthon
Jun 12 '13 at 7:09
+1 I do not understand the downvotes either, simply because this is something which has bugged me many times before, and it seems impossible to find anything concise and useful about this specific theme.
– l0b0
Jun 12 '13 at 7:52
@Mohsen I didn't downvote but the difference to the question you linked is that there is noswitch
in ruby while you can set directly the date viadate -s
(as shown in the manpage), or use any of the commands described below...
– Ulrich Dangel
Jun 12 '13 at 8:33
1
@Anthon I disagree: that question is about a small device with BusyBox, which makes the generic advice “use NTP” not necessarily applicable
– Gilles
Jun 12 '13 at 22:55
|
show 3 more comments
How do I retrieve the date from the Internet and set my computer's clock, from the command line?
command-line date remote clock
How do I retrieve the date from the Internet and set my computer's clock, from the command line?
command-line date remote clock
command-line date remote clock
edited Jun 12 '13 at 22:57
Gilles
551k13211241637
551k13211241637
asked Jun 12 '13 at 5:40
MohsenMohsen
90021527
90021527
2
I do not understand downvotes. Simple questions are what make a community powerful. For example see this
– Mohsen
Jun 12 '13 at 6:35
3
When I hover above a question's down arrow with my mouse I see: "This question does not show any research effort; it is unclear or not useful". I would be tempted to downvote your question based on the first (no indication of what you found), the second (no indication on what specific platform you are working on, and why this has to be commandline (instead of the usual time daemon)) and the third (most *nix users will have some time daemon installed by default).
– Anthon
Jun 12 '13 at 7:09
+1 I do not understand the downvotes either, simply because this is something which has bugged me many times before, and it seems impossible to find anything concise and useful about this specific theme.
– l0b0
Jun 12 '13 at 7:52
@Mohsen I didn't downvote but the difference to the question you linked is that there is noswitch
in ruby while you can set directly the date viadate -s
(as shown in the manpage), or use any of the commands described below...
– Ulrich Dangel
Jun 12 '13 at 8:33
1
@Anthon I disagree: that question is about a small device with BusyBox, which makes the generic advice “use NTP” not necessarily applicable
– Gilles
Jun 12 '13 at 22:55
|
show 3 more comments
2
I do not understand downvotes. Simple questions are what make a community powerful. For example see this
– Mohsen
Jun 12 '13 at 6:35
3
When I hover above a question's down arrow with my mouse I see: "This question does not show any research effort; it is unclear or not useful". I would be tempted to downvote your question based on the first (no indication of what you found), the second (no indication on what specific platform you are working on, and why this has to be commandline (instead of the usual time daemon)) and the third (most *nix users will have some time daemon installed by default).
– Anthon
Jun 12 '13 at 7:09
+1 I do not understand the downvotes either, simply because this is something which has bugged me many times before, and it seems impossible to find anything concise and useful about this specific theme.
– l0b0
Jun 12 '13 at 7:52
@Mohsen I didn't downvote but the difference to the question you linked is that there is noswitch
in ruby while you can set directly the date viadate -s
(as shown in the manpage), or use any of the commands described below...
– Ulrich Dangel
Jun 12 '13 at 8:33
1
@Anthon I disagree: that question is about a small device with BusyBox, which makes the generic advice “use NTP” not necessarily applicable
– Gilles
Jun 12 '13 at 22:55
2
2
I do not understand downvotes. Simple questions are what make a community powerful. For example see this
– Mohsen
Jun 12 '13 at 6:35
I do not understand downvotes. Simple questions are what make a community powerful. For example see this
– Mohsen
Jun 12 '13 at 6:35
3
3
When I hover above a question's down arrow with my mouse I see: "This question does not show any research effort; it is unclear or not useful". I would be tempted to downvote your question based on the first (no indication of what you found), the second (no indication on what specific platform you are working on, and why this has to be commandline (instead of the usual time daemon)) and the third (most *nix users will have some time daemon installed by default).
– Anthon
Jun 12 '13 at 7:09
When I hover above a question's down arrow with my mouse I see: "This question does not show any research effort; it is unclear or not useful". I would be tempted to downvote your question based on the first (no indication of what you found), the second (no indication on what specific platform you are working on, and why this has to be commandline (instead of the usual time daemon)) and the third (most *nix users will have some time daemon installed by default).
– Anthon
Jun 12 '13 at 7:09
+1 I do not understand the downvotes either, simply because this is something which has bugged me many times before, and it seems impossible to find anything concise and useful about this specific theme.
– l0b0
Jun 12 '13 at 7:52
+1 I do not understand the downvotes either, simply because this is something which has bugged me many times before, and it seems impossible to find anything concise and useful about this specific theme.
– l0b0
Jun 12 '13 at 7:52
@Mohsen I didn't downvote but the difference to the question you linked is that there is no
switch
in ruby while you can set directly the date via date -s
(as shown in the manpage), or use any of the commands described below...– Ulrich Dangel
Jun 12 '13 at 8:33
@Mohsen I didn't downvote but the difference to the question you linked is that there is no
switch
in ruby while you can set directly the date via date -s
(as shown in the manpage), or use any of the commands described below...– Ulrich Dangel
Jun 12 '13 at 8:33
1
1
@Anthon I disagree: that question is about a small device with BusyBox, which makes the generic advice “use NTP” not necessarily applicable
– Gilles
Jun 12 '13 at 22:55
@Anthon I disagree: that question is about a small device with BusyBox, which makes the generic advice “use NTP” not necessarily applicable
– Gilles
Jun 12 '13 at 22:55
|
show 3 more comments
10 Answers
10
active
oldest
votes
You can use :
sudo dpkg-reconfigure tzdata
for configuring your timezone .
For updating time and date from internet use the following :
Install
If ntpd is not installed use any one of the following command to install ntpd:
For RPM based:
yum install ntp
For Debian based:
sudo apt-get install ntp
Configuration
You should at least set following parameter in /etc/ntp.conf config file:
server
For example, open /etc/ntp.conf file using vi text editor:
# vi /etc/ntp.conf
Locate server parameter and set it as follows:
server pool.ntp.org
Save the file and restart the ntpd service:
# /etc/init.d/ntpd start
You can synchronize the system clock to an NTP server immediately with following command:
# ntpdate pool.ntp.org
*For setting the time and date manually use the following syntax:
date --set="STRING"
For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
# date -s "2 OCT 2006 18:00:00"
OR
# date --set="2 OCT 2006 18:00:00"
You can also simplify format using following syntax:
# date +%Y%m%d -s "20081128"
To set time use the following syntax:
# date +%T -s "10:13:13"
Where,
10: Hour (hh)
13: Minute (mm)
13: Second (ss)
Use %p locale’s equivalent of either AM or PM, enter:
# date +%T%p -s "6:10:30AM"
# date +%T%p -s "12:10:30PM"
Although the date information seems all valid, it does not take the requirementfrom the internet
from the title of the OP into account anywhere.
– Anthon
Jun 12 '13 at 7:03
I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .
– tusharmakkar08
Jun 12 '13 at 7:26
3
tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.
– Anthon
Jun 12 '13 at 7:42
You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.
– Ulrich Dangel
Jun 12 '13 at 8:32
@Anthon : I have edited my answer correspondingly.Thank You.
– tusharmakkar08
Jun 12 '13 at 9:43
|
show 3 more comments
A small code I found to update your time in case you don't want to install anything just to update the date. :)
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
1
I usegoogle.in
to get the current time for my timezone (INDIA).
– Dilawar
Jul 25 '18 at 12:35
Note the trailingZ
which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.
– user202729
Sep 6 '18 at 13:13
add a comment |
I use this:
sudo ntpd -qg; sudo hwclock -w
first tell ntpd to just set the time and stop after that with -q. Also, in case a your clock has a big error we need to tell ntpd to also adjust in that case with -g. Finally write the clock to hardware to preserve the changes when rebooting with hwclock -w (-w for setting hardwareclock to current system time, there is a difference).
1
i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited
– Theophrastus
Sep 19 '15 at 20:06
add a comment |
Use ntpdate, ntpd, or Chrony to connect to a NTP server.
add a comment |
Some distributions are shipping rdate for that purpose. Basic usage:
# just query
bash-4.2$ rdate pool.ntp.org
rdate: [pool.ntp.org] Wed Jun 12 11:05:40 2013
# set system time
bash-4.2$ rdate -s pool.ntp.org
Way better and easier than ntp
– andrewtweber
Mar 30 '16 at 18:39
pool.ntp.org
now refuses connections fromrdate
.time.nist.gov
works. Also once you have set the system time, you should set the hardware clock as well by runninghwclock -w
to set it to the system time. You can then verify it is correct by runninghwclock -r
– MatthewLee
Jul 14 '17 at 14:53
add a comment |
After some research, I ended up with this. I also applied it to my own server:
sudo apt-get install ntp
sudo dpkg-reconfigure ntp
ntpq -p
If the last command shows a valid list of servers, you are good to go. The command will run a quite complex set of algorithms which will iterate your clock drift, among other things, and compensate for them. You will end up with a pretty accurate clock even if you lose the connection to the NTP servers. However, the command does require a few minutes to get started.
Source: here and here.
add a comment |
To find "peers" (hosts you can query) you can use ntpq -p
.
If you already have an NTP service running you have to stop it before manually updating, for example using sudo service ntp stop
.
Now you can query a peer, for example using sudo ntpdate "peer"
.
add a comment |
Using rdate tool as suggested in manatwork's answer, but with SNTP protocol -n
and IPv4 -4
options on:
# just print synced time, not set
rdate -n -4 -p time-a.nist.gov
# print and set synced time
sudo rdate -n -4 time-a.nist.gov
The tool may be installed on Debian this way:
sudo apt-get install rdate
add a comment |
In addition to Tushar's reply, I also had to do apt-get install ntpdate
on my Ubuntu 14.04.
Posting as answer because reputation does not suffice for commenting.
add a comment |
I also was looking for a non ntp/ntpd way of resetting clock periodically. I liked the google.com header parsing but found it did not work on ubuntu. I think this will also work on a Raspberry Pi.
sudo date +"%d %b %Y %T %Z" -s "$(wget -qSO- --max-redirect=0 http://google.com 2>&1 | grep '^ Date:' | cut -d' ' -f 5-)"
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f79112%2fhow-do-i-set-time-and-date-from-the-internet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
10 Answers
10
active
oldest
votes
10 Answers
10
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use :
sudo dpkg-reconfigure tzdata
for configuring your timezone .
For updating time and date from internet use the following :
Install
If ntpd is not installed use any one of the following command to install ntpd:
For RPM based:
yum install ntp
For Debian based:
sudo apt-get install ntp
Configuration
You should at least set following parameter in /etc/ntp.conf config file:
server
For example, open /etc/ntp.conf file using vi text editor:
# vi /etc/ntp.conf
Locate server parameter and set it as follows:
server pool.ntp.org
Save the file and restart the ntpd service:
# /etc/init.d/ntpd start
You can synchronize the system clock to an NTP server immediately with following command:
# ntpdate pool.ntp.org
*For setting the time and date manually use the following syntax:
date --set="STRING"
For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
# date -s "2 OCT 2006 18:00:00"
OR
# date --set="2 OCT 2006 18:00:00"
You can also simplify format using following syntax:
# date +%Y%m%d -s "20081128"
To set time use the following syntax:
# date +%T -s "10:13:13"
Where,
10: Hour (hh)
13: Minute (mm)
13: Second (ss)
Use %p locale’s equivalent of either AM or PM, enter:
# date +%T%p -s "6:10:30AM"
# date +%T%p -s "12:10:30PM"
Although the date information seems all valid, it does not take the requirementfrom the internet
from the title of the OP into account anywhere.
– Anthon
Jun 12 '13 at 7:03
I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .
– tusharmakkar08
Jun 12 '13 at 7:26
3
tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.
– Anthon
Jun 12 '13 at 7:42
You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.
– Ulrich Dangel
Jun 12 '13 at 8:32
@Anthon : I have edited my answer correspondingly.Thank You.
– tusharmakkar08
Jun 12 '13 at 9:43
|
show 3 more comments
You can use :
sudo dpkg-reconfigure tzdata
for configuring your timezone .
For updating time and date from internet use the following :
Install
If ntpd is not installed use any one of the following command to install ntpd:
For RPM based:
yum install ntp
For Debian based:
sudo apt-get install ntp
Configuration
You should at least set following parameter in /etc/ntp.conf config file:
server
For example, open /etc/ntp.conf file using vi text editor:
# vi /etc/ntp.conf
Locate server parameter and set it as follows:
server pool.ntp.org
Save the file and restart the ntpd service:
# /etc/init.d/ntpd start
You can synchronize the system clock to an NTP server immediately with following command:
# ntpdate pool.ntp.org
*For setting the time and date manually use the following syntax:
date --set="STRING"
For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
# date -s "2 OCT 2006 18:00:00"
OR
# date --set="2 OCT 2006 18:00:00"
You can also simplify format using following syntax:
# date +%Y%m%d -s "20081128"
To set time use the following syntax:
# date +%T -s "10:13:13"
Where,
10: Hour (hh)
13: Minute (mm)
13: Second (ss)
Use %p locale’s equivalent of either AM or PM, enter:
# date +%T%p -s "6:10:30AM"
# date +%T%p -s "12:10:30PM"
Although the date information seems all valid, it does not take the requirementfrom the internet
from the title of the OP into account anywhere.
– Anthon
Jun 12 '13 at 7:03
I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .
– tusharmakkar08
Jun 12 '13 at 7:26
3
tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.
– Anthon
Jun 12 '13 at 7:42
You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.
– Ulrich Dangel
Jun 12 '13 at 8:32
@Anthon : I have edited my answer correspondingly.Thank You.
– tusharmakkar08
Jun 12 '13 at 9:43
|
show 3 more comments
You can use :
sudo dpkg-reconfigure tzdata
for configuring your timezone .
For updating time and date from internet use the following :
Install
If ntpd is not installed use any one of the following command to install ntpd:
For RPM based:
yum install ntp
For Debian based:
sudo apt-get install ntp
Configuration
You should at least set following parameter in /etc/ntp.conf config file:
server
For example, open /etc/ntp.conf file using vi text editor:
# vi /etc/ntp.conf
Locate server parameter and set it as follows:
server pool.ntp.org
Save the file and restart the ntpd service:
# /etc/init.d/ntpd start
You can synchronize the system clock to an NTP server immediately with following command:
# ntpdate pool.ntp.org
*For setting the time and date manually use the following syntax:
date --set="STRING"
For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
# date -s "2 OCT 2006 18:00:00"
OR
# date --set="2 OCT 2006 18:00:00"
You can also simplify format using following syntax:
# date +%Y%m%d -s "20081128"
To set time use the following syntax:
# date +%T -s "10:13:13"
Where,
10: Hour (hh)
13: Minute (mm)
13: Second (ss)
Use %p locale’s equivalent of either AM or PM, enter:
# date +%T%p -s "6:10:30AM"
# date +%T%p -s "12:10:30PM"
You can use :
sudo dpkg-reconfigure tzdata
for configuring your timezone .
For updating time and date from internet use the following :
Install
If ntpd is not installed use any one of the following command to install ntpd:
For RPM based:
yum install ntp
For Debian based:
sudo apt-get install ntp
Configuration
You should at least set following parameter in /etc/ntp.conf config file:
server
For example, open /etc/ntp.conf file using vi text editor:
# vi /etc/ntp.conf
Locate server parameter and set it as follows:
server pool.ntp.org
Save the file and restart the ntpd service:
# /etc/init.d/ntpd start
You can synchronize the system clock to an NTP server immediately with following command:
# ntpdate pool.ntp.org
*For setting the time and date manually use the following syntax:
date --set="STRING"
For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
# date -s "2 OCT 2006 18:00:00"
OR
# date --set="2 OCT 2006 18:00:00"
You can also simplify format using following syntax:
# date +%Y%m%d -s "20081128"
To set time use the following syntax:
# date +%T -s "10:13:13"
Where,
10: Hour (hh)
13: Minute (mm)
13: Second (ss)
Use %p locale’s equivalent of either AM or PM, enter:
# date +%T%p -s "6:10:30AM"
# date +%T%p -s "12:10:30PM"
edited Aug 3 '16 at 8:59
Kusalananda♦
145k18273452
145k18273452
answered Jun 12 '13 at 6:06
tusharmakkar08tusharmakkar08
94711221
94711221
Although the date information seems all valid, it does not take the requirementfrom the internet
from the title of the OP into account anywhere.
– Anthon
Jun 12 '13 at 7:03
I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .
– tusharmakkar08
Jun 12 '13 at 7:26
3
tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.
– Anthon
Jun 12 '13 at 7:42
You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.
– Ulrich Dangel
Jun 12 '13 at 8:32
@Anthon : I have edited my answer correspondingly.Thank You.
– tusharmakkar08
Jun 12 '13 at 9:43
|
show 3 more comments
Although the date information seems all valid, it does not take the requirementfrom the internet
from the title of the OP into account anywhere.
– Anthon
Jun 12 '13 at 7:03
I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .
– tusharmakkar08
Jun 12 '13 at 7:26
3
tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.
– Anthon
Jun 12 '13 at 7:42
You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.
– Ulrich Dangel
Jun 12 '13 at 8:32
@Anthon : I have edited my answer correspondingly.Thank You.
– tusharmakkar08
Jun 12 '13 at 9:43
Although the date information seems all valid, it does not take the requirement
from the internet
from the title of the OP into account anywhere.– Anthon
Jun 12 '13 at 7:03
Although the date information seems all valid, it does not take the requirement
from the internet
from the title of the OP into account anywhere.– Anthon
Jun 12 '13 at 7:03
I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .
– tusharmakkar08
Jun 12 '13 at 7:26
I believe that tzdata (time zone data) package synchronizes the data from internet only. Correct me if I am wrong .
– tusharmakkar08
Jun 12 '13 at 7:26
3
3
tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.
– Anthon
Jun 12 '13 at 7:42
tzdata is information about timezones and daylight saving time (start, end, epoch) not the actual date and time. Of course that is handy to know how to get to your local time based on knowledge of your timezone and a UTC time, but you still need to retrieve the latter from the internet.
– Anthon
Jun 12 '13 at 7:42
You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.
– Ulrich Dangel
Jun 12 '13 at 8:32
You are wrong. time zone data has to be updated (as there are changes happening all the time) BUT it does not update itself automatically from the internet NOR does it set the time from the internet.
– Ulrich Dangel
Jun 12 '13 at 8:32
@Anthon : I have edited my answer correspondingly.Thank You.
– tusharmakkar08
Jun 12 '13 at 9:43
@Anthon : I have edited my answer correspondingly.Thank You.
– tusharmakkar08
Jun 12 '13 at 9:43
|
show 3 more comments
A small code I found to update your time in case you don't want to install anything just to update the date. :)
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
1
I usegoogle.in
to get the current time for my timezone (INDIA).
– Dilawar
Jul 25 '18 at 12:35
Note the trailingZ
which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.
– user202729
Sep 6 '18 at 13:13
add a comment |
A small code I found to update your time in case you don't want to install anything just to update the date. :)
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
1
I usegoogle.in
to get the current time for my timezone (INDIA).
– Dilawar
Jul 25 '18 at 12:35
Note the trailingZ
which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.
– user202729
Sep 6 '18 at 13:13
add a comment |
A small code I found to update your time in case you don't want to install anything just to update the date. :)
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
A small code I found to update your time in case you don't want to install anything just to update the date. :)
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
answered Oct 24 '17 at 15:30
Prashant KabadePrashant Kabade
30123
30123
1
I usegoogle.in
to get the current time for my timezone (INDIA).
– Dilawar
Jul 25 '18 at 12:35
Note the trailingZ
which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.
– user202729
Sep 6 '18 at 13:13
add a comment |
1
I usegoogle.in
to get the current time for my timezone (INDIA).
– Dilawar
Jul 25 '18 at 12:35
Note the trailingZ
which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.
– user202729
Sep 6 '18 at 13:13
1
1
I use
google.in
to get the current time for my timezone (INDIA).– Dilawar
Jul 25 '18 at 12:35
I use
google.in
to get the current time for my timezone (INDIA).– Dilawar
Jul 25 '18 at 12:35
Note the trailing
Z
which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.– user202729
Sep 6 '18 at 13:13
Note the trailing
Z
which indicates that the time is given in zulu time zone, so no special timezone manipulation should be needed if the computer timezone is set correctly.– user202729
Sep 6 '18 at 13:13
add a comment |
I use this:
sudo ntpd -qg; sudo hwclock -w
first tell ntpd to just set the time and stop after that with -q. Also, in case a your clock has a big error we need to tell ntpd to also adjust in that case with -g. Finally write the clock to hardware to preserve the changes when rebooting with hwclock -w (-w for setting hardwareclock to current system time, there is a difference).
1
i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited
– Theophrastus
Sep 19 '15 at 20:06
add a comment |
I use this:
sudo ntpd -qg; sudo hwclock -w
first tell ntpd to just set the time and stop after that with -q. Also, in case a your clock has a big error we need to tell ntpd to also adjust in that case with -g. Finally write the clock to hardware to preserve the changes when rebooting with hwclock -w (-w for setting hardwareclock to current system time, there is a difference).
1
i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited
– Theophrastus
Sep 19 '15 at 20:06
add a comment |
I use this:
sudo ntpd -qg; sudo hwclock -w
first tell ntpd to just set the time and stop after that with -q. Also, in case a your clock has a big error we need to tell ntpd to also adjust in that case with -g. Finally write the clock to hardware to preserve the changes when rebooting with hwclock -w (-w for setting hardwareclock to current system time, there is a difference).
I use this:
sudo ntpd -qg; sudo hwclock -w
first tell ntpd to just set the time and stop after that with -q. Also, in case a your clock has a big error we need to tell ntpd to also adjust in that case with -g. Finally write the clock to hardware to preserve the changes when rebooting with hwclock -w (-w for setting hardwareclock to current system time, there is a difference).
answered Jun 12 '13 at 8:58
SilverrockerSilverrocker
1,197920
1,197920
1
i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited
– Theophrastus
Sep 19 '15 at 20:06
add a comment |
1
i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited
– Theophrastus
Sep 19 '15 at 20:06
1
1
i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited
– Theophrastus
Sep 19 '15 at 20:06
i tend to do this with a "&&" instead of the semicolon so that if the first command should fail (e.g. network connectivity down) the second command is short-circuited
– Theophrastus
Sep 19 '15 at 20:06
add a comment |
Use ntpdate, ntpd, or Chrony to connect to a NTP server.
add a comment |
Use ntpdate, ntpd, or Chrony to connect to a NTP server.
add a comment |
Use ntpdate, ntpd, or Chrony to connect to a NTP server.
Use ntpdate, ntpd, or Chrony to connect to a NTP server.
answered Jun 12 '13 at 5:42
Ignacio Vazquez-AbramsIgnacio Vazquez-Abrams
34k66984
34k66984
add a comment |
add a comment |
Some distributions are shipping rdate for that purpose. Basic usage:
# just query
bash-4.2$ rdate pool.ntp.org
rdate: [pool.ntp.org] Wed Jun 12 11:05:40 2013
# set system time
bash-4.2$ rdate -s pool.ntp.org
Way better and easier than ntp
– andrewtweber
Mar 30 '16 at 18:39
pool.ntp.org
now refuses connections fromrdate
.time.nist.gov
works. Also once you have set the system time, you should set the hardware clock as well by runninghwclock -w
to set it to the system time. You can then verify it is correct by runninghwclock -r
– MatthewLee
Jul 14 '17 at 14:53
add a comment |
Some distributions are shipping rdate for that purpose. Basic usage:
# just query
bash-4.2$ rdate pool.ntp.org
rdate: [pool.ntp.org] Wed Jun 12 11:05:40 2013
# set system time
bash-4.2$ rdate -s pool.ntp.org
Way better and easier than ntp
– andrewtweber
Mar 30 '16 at 18:39
pool.ntp.org
now refuses connections fromrdate
.time.nist.gov
works. Also once you have set the system time, you should set the hardware clock as well by runninghwclock -w
to set it to the system time. You can then verify it is correct by runninghwclock -r
– MatthewLee
Jul 14 '17 at 14:53
add a comment |
Some distributions are shipping rdate for that purpose. Basic usage:
# just query
bash-4.2$ rdate pool.ntp.org
rdate: [pool.ntp.org] Wed Jun 12 11:05:40 2013
# set system time
bash-4.2$ rdate -s pool.ntp.org
Some distributions are shipping rdate for that purpose. Basic usage:
# just query
bash-4.2$ rdate pool.ntp.org
rdate: [pool.ntp.org] Wed Jun 12 11:05:40 2013
# set system time
bash-4.2$ rdate -s pool.ntp.org
answered Jun 12 '13 at 8:07
manatworkmanatwork
22.4k38386
22.4k38386
Way better and easier than ntp
– andrewtweber
Mar 30 '16 at 18:39
pool.ntp.org
now refuses connections fromrdate
.time.nist.gov
works. Also once you have set the system time, you should set the hardware clock as well by runninghwclock -w
to set it to the system time. You can then verify it is correct by runninghwclock -r
– MatthewLee
Jul 14 '17 at 14:53
add a comment |
Way better and easier than ntp
– andrewtweber
Mar 30 '16 at 18:39
pool.ntp.org
now refuses connections fromrdate
.time.nist.gov
works. Also once you have set the system time, you should set the hardware clock as well by runninghwclock -w
to set it to the system time. You can then verify it is correct by runninghwclock -r
– MatthewLee
Jul 14 '17 at 14:53
Way better and easier than ntp
– andrewtweber
Mar 30 '16 at 18:39
Way better and easier than ntp
– andrewtweber
Mar 30 '16 at 18:39
pool.ntp.org
now refuses connections from rdate
. time.nist.gov
works. Also once you have set the system time, you should set the hardware clock as well by running hwclock -w
to set it to the system time. You can then verify it is correct by running hwclock -r
– MatthewLee
Jul 14 '17 at 14:53
pool.ntp.org
now refuses connections from rdate
. time.nist.gov
works. Also once you have set the system time, you should set the hardware clock as well by running hwclock -w
to set it to the system time. You can then verify it is correct by running hwclock -r
– MatthewLee
Jul 14 '17 at 14:53
add a comment |
After some research, I ended up with this. I also applied it to my own server:
sudo apt-get install ntp
sudo dpkg-reconfigure ntp
ntpq -p
If the last command shows a valid list of servers, you are good to go. The command will run a quite complex set of algorithms which will iterate your clock drift, among other things, and compensate for them. You will end up with a pretty accurate clock even if you lose the connection to the NTP servers. However, the command does require a few minutes to get started.
Source: here and here.
add a comment |
After some research, I ended up with this. I also applied it to my own server:
sudo apt-get install ntp
sudo dpkg-reconfigure ntp
ntpq -p
If the last command shows a valid list of servers, you are good to go. The command will run a quite complex set of algorithms which will iterate your clock drift, among other things, and compensate for them. You will end up with a pretty accurate clock even if you lose the connection to the NTP servers. However, the command does require a few minutes to get started.
Source: here and here.
add a comment |
After some research, I ended up with this. I also applied it to my own server:
sudo apt-get install ntp
sudo dpkg-reconfigure ntp
ntpq -p
If the last command shows a valid list of servers, you are good to go. The command will run a quite complex set of algorithms which will iterate your clock drift, among other things, and compensate for them. You will end up with a pretty accurate clock even if you lose the connection to the NTP servers. However, the command does require a few minutes to get started.
Source: here and here.
After some research, I ended up with this. I also applied it to my own server:
sudo apt-get install ntp
sudo dpkg-reconfigure ntp
ntpq -p
If the last command shows a valid list of servers, you are good to go. The command will run a quite complex set of algorithms which will iterate your clock drift, among other things, and compensate for them. You will end up with a pretty accurate clock even if you lose the connection to the NTP servers. However, the command does require a few minutes to get started.
Source: here and here.
answered Mar 30 '15 at 20:00
TubblesTubbles
412
412
add a comment |
add a comment |
To find "peers" (hosts you can query) you can use ntpq -p
.
If you already have an NTP service running you have to stop it before manually updating, for example using sudo service ntp stop
.
Now you can query a peer, for example using sudo ntpdate "peer"
.
add a comment |
To find "peers" (hosts you can query) you can use ntpq -p
.
If you already have an NTP service running you have to stop it before manually updating, for example using sudo service ntp stop
.
Now you can query a peer, for example using sudo ntpdate "peer"
.
add a comment |
To find "peers" (hosts you can query) you can use ntpq -p
.
If you already have an NTP service running you have to stop it before manually updating, for example using sudo service ntp stop
.
Now you can query a peer, for example using sudo ntpdate "peer"
.
To find "peers" (hosts you can query) you can use ntpq -p
.
If you already have an NTP service running you have to stop it before manually updating, for example using sudo service ntp stop
.
Now you can query a peer, for example using sudo ntpdate "peer"
.
answered Jun 12 '13 at 7:55
l0b0l0b0
29k20122252
29k20122252
add a comment |
add a comment |
Using rdate tool as suggested in manatwork's answer, but with SNTP protocol -n
and IPv4 -4
options on:
# just print synced time, not set
rdate -n -4 -p time-a.nist.gov
# print and set synced time
sudo rdate -n -4 time-a.nist.gov
The tool may be installed on Debian this way:
sudo apt-get install rdate
add a comment |
Using rdate tool as suggested in manatwork's answer, but with SNTP protocol -n
and IPv4 -4
options on:
# just print synced time, not set
rdate -n -4 -p time-a.nist.gov
# print and set synced time
sudo rdate -n -4 time-a.nist.gov
The tool may be installed on Debian this way:
sudo apt-get install rdate
add a comment |
Using rdate tool as suggested in manatwork's answer, but with SNTP protocol -n
and IPv4 -4
options on:
# just print synced time, not set
rdate -n -4 -p time-a.nist.gov
# print and set synced time
sudo rdate -n -4 time-a.nist.gov
The tool may be installed on Debian this way:
sudo apt-get install rdate
Using rdate tool as suggested in manatwork's answer, but with SNTP protocol -n
and IPv4 -4
options on:
# just print synced time, not set
rdate -n -4 -p time-a.nist.gov
# print and set synced time
sudo rdate -n -4 time-a.nist.gov
The tool may be installed on Debian this way:
sudo apt-get install rdate
answered Sep 19 '15 at 19:19
SergeanTSergeanT
1012
1012
add a comment |
add a comment |
In addition to Tushar's reply, I also had to do apt-get install ntpdate
on my Ubuntu 14.04.
Posting as answer because reputation does not suffice for commenting.
add a comment |
In addition to Tushar's reply, I also had to do apt-get install ntpdate
on my Ubuntu 14.04.
Posting as answer because reputation does not suffice for commenting.
add a comment |
In addition to Tushar's reply, I also had to do apt-get install ntpdate
on my Ubuntu 14.04.
Posting as answer because reputation does not suffice for commenting.
In addition to Tushar's reply, I also had to do apt-get install ntpdate
on my Ubuntu 14.04.
Posting as answer because reputation does not suffice for commenting.
edited Apr 13 '17 at 12:36
Community♦
1
1
answered Feb 7 '17 at 16:21
pylipppylipp
32
32
add a comment |
add a comment |
I also was looking for a non ntp/ntpd way of resetting clock periodically. I liked the google.com header parsing but found it did not work on ubuntu. I think this will also work on a Raspberry Pi.
sudo date +"%d %b %Y %T %Z" -s "$(wget -qSO- --max-redirect=0 http://google.com 2>&1 | grep '^ Date:' | cut -d' ' -f 5-)"
New contributor
add a comment |
I also was looking for a non ntp/ntpd way of resetting clock periodically. I liked the google.com header parsing but found it did not work on ubuntu. I think this will also work on a Raspberry Pi.
sudo date +"%d %b %Y %T %Z" -s "$(wget -qSO- --max-redirect=0 http://google.com 2>&1 | grep '^ Date:' | cut -d' ' -f 5-)"
New contributor
add a comment |
I also was looking for a non ntp/ntpd way of resetting clock periodically. I liked the google.com header parsing but found it did not work on ubuntu. I think this will also work on a Raspberry Pi.
sudo date +"%d %b %Y %T %Z" -s "$(wget -qSO- --max-redirect=0 http://google.com 2>&1 | grep '^ Date:' | cut -d' ' -f 5-)"
New contributor
I also was looking for a non ntp/ntpd way of resetting clock periodically. I liked the google.com header parsing but found it did not work on ubuntu. I think this will also work on a Raspberry Pi.
sudo date +"%d %b %Y %T %Z" -s "$(wget -qSO- --max-redirect=0 http://google.com 2>&1 | grep '^ Date:' | cut -d' ' -f 5-)"
New contributor
New contributor
answered 15 mins ago
Ron BRon B
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f79112%2fhow-do-i-set-time-and-date-from-the-internet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
I do not understand downvotes. Simple questions are what make a community powerful. For example see this
– Mohsen
Jun 12 '13 at 6:35
3
When I hover above a question's down arrow with my mouse I see: "This question does not show any research effort; it is unclear or not useful". I would be tempted to downvote your question based on the first (no indication of what you found), the second (no indication on what specific platform you are working on, and why this has to be commandline (instead of the usual time daemon)) and the third (most *nix users will have some time daemon installed by default).
– Anthon
Jun 12 '13 at 7:09
+1 I do not understand the downvotes either, simply because this is something which has bugged me many times before, and it seems impossible to find anything concise and useful about this specific theme.
– l0b0
Jun 12 '13 at 7:52
@Mohsen I didn't downvote but the difference to the question you linked is that there is no
switch
in ruby while you can set directly the date viadate -s
(as shown in the manpage), or use any of the commands described below...– Ulrich Dangel
Jun 12 '13 at 8:33
1
@Anthon I disagree: that question is about a small device with BusyBox, which makes the generic advice “use NTP” not necessarily applicable
– Gilles
Jun 12 '13 at 22:55