How to set time

How to do things, solutions, recipes, tutorials
Message
Author
labbe5
Posts: 2159
Joined: Wed 13 Nov 2013, 14:26
Location: Canada

How to set time

#1 Post by labbe5 »

In Trinitydog :

First, i installed ntp.
Then i added ca.pool.ntp.org in /etc/systemd/timesyncd.conf.

The file looks like this :

[Time]
NTP=ca.pool.ntp.org #nearest server for me

Testing in terminal :
timedatectl status

Resulting values :
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no

Finally, reboot.
Now time should be correct.

In Stretchdog with Openbox (from mklive-stretch script & default config)

An alternative way of setting system time.

UTC is used, and there is a mismatch between UTC and local time.

To set the time :
# date -s hh:mm:ss #in Conky, UTC is now set to local time
To set the hardware clock :
# hwclock --systohc --utc

Now local time is ok and is set persistently.

Website of interest related to time zones : http://www.timebie.com/std/edt.php?q=15.5

Further reading :
http://www.putorius.net/2015/04/setting ... hat-7.html
Last edited by labbe5 on Thu 12 Oct 2017, 13:41, edited 3 times in total.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#2 Post by musher0 »

Hello all.

Here is another thread on sync'ing the time on your computer with
an ntp server.

BFN.
:
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#3 Post by Flash »

There's also https://time.gov/.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#4 Post by musher0 »

Flash wrote:There's also https://time.gov/.
Hi Flash.

Limited to users in the US, I presume? Also, can it set or correct the current
time automatically on your computer?

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#5 Post by Flash »

It won't cost you anything to try it and see if it works in another country. Australia would be a definitive test.

I'm sure the NIST time signal is designed so that computers and other hardware can set themselves with it without human intervention. There are instructions on the time.gov web site for how to make your computer do just that. See this page under "Setting your computer clock."

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#6 Post by musher0 »

Flash wrote:It won't cost you anything to try it and see if it works in another country. Australia would be a definitive test.

I'm sure the NIST time signal is designed so that computers and other hardware can set themselves with it without human intervention. There are instructions on the time.gov web site for how to make your computer do just that. See this page under "Setting your computer clock."
Hi Flash.

To set the time automatically on your compuiter, the NIST site is basically
telling you (in other words): "Use the ntp protocol!" (hehe)

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#7 Post by Flash »

Okay, but don't you get to use their time signal? I don't think Trump has found out about NIST yet, so maybe they can be trusted.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#8 Post by musher0 »

Flash wrote:Okay, but don't you get to use their time signal? I don't think Trump has found out about NIST yet, so maybe they can be trusted.
Forget NIST!!! Trump can shut it down if he wants to!

As I am writing these lines, there are 813 other ntp servers in activity in
the USA, says http://www.pool.ntp.org/zone/us.

The way ntp works, your computer hooks up to one of the servers in the
us.pool.ntp.org domain, and they try to hook you up with the one closest
to your location.

Please correct me if I'm wrong, but as I understand it, NIST, the National
Research Center of Canada, and other major national science institutes in
various countries participate in defining Greenwich Mean Time. This data is
in turn distributed back to ntp servers in the World Time Zones, with a
precision of a millionth of a second, apparently.

Not that I wish it, but theoretically Trump can shut down your NIST institute,
and you'll still get correct time for your location through any other ntp
server in US.

With your knowledge of networks, Flash, you could probably set up an ntp
server for the Puppy community. Apparently they are easy to set up.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

zagreb999
Posts: 567
Joined: Fri 11 Apr 2014, 06:39
Location: Yugoslavija

time

#9 Post by zagreb999 »

regards

to set the time,
use this
tzclock_3.0.6-1_i386.deb

works perfectly

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#10 Post by vovchik »

Dear all,

A very easy way to set the time is with, for example:

Code: Select all

htpdate -s www.google.at
It grabs the server time and date (use a server in your time zone) and can set your clock and kernel time, too.

I started using that with my Raspberry PI, which has no built-in baterry powered clock, and I run that at start-up, once a network connection has been established. It is much easier than geting NTP servers to work properly. The htpdate prog is available in deb repositories...and must exist for Slack as well.

With kind regards,
vovchik

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#11 Post by musher0 »

Hi vovchik.

DPupStretch-7 does not have the htpdate utility!

Do the other Puppies have it?

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#12 Post by musher0 »

Hm...
Frequently Asked Questions

Why should I use htpdate?

You shouldn't, use NTP if you can. NTP is much more accurate.... however
NTP doesn't work in combination with proxy servers. Also NTP network traffic
(UDP port 123) is often blocked by firewalls and doesn't always work if you
are behind a NAT device. If you have access to websites, htpdate will work.
Source: http://www.vervest.org/htp/FAQ

In any case, here are some Debian binaries:
https://packages.debian.org/search?keywords=htpdate

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Pelo

with my outdated Slacko 64

#13 Post by Pelo »

with my outdated Slacko 64 6.9.6.4 there is an error message 'clock time is in the future.'
could the reason be that i am in France, so in advance of at least six hours compared to USA ?
First settings let at USA..
On which time are set Puppies, when delivered to dowloaders : greenwich, australia, Paris or Gâtineau ? Who does it, the Puppy-builder ?
First settings : if i choose Paris, time 18:44 is wrong, it's 16:44 (untick UTC , then good)
old how-to topic by kpfuser
Menu/desktop/ date and time, is the usual method.
Attachments
puertorico.jpg
irma, antilles françaises
(47.24 KiB) Downloaded 588 times
Last edited by Pelo on Mon 11 Sep 2017, 14:55, edited 1 time in total.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#14 Post by musher0 »

Pelo wrote:with my outdated Slacko 64 6.9.6.4 there is an error message 'clock time
is in the future.' could the reason be that i am in France, so in advance of
at least six hours compared to USA ? First settings let at USA.
No, it's not the fact that you are located in France. I don't know the actual
reason, I've seen the "time in the future" sentence too. Sometimes the
initial time of the Puppy is set to Los Angeles, sometimes to a city in
Australia.
Pelo wrote:On which time are set Puppies, when delivered to dowloaders : greenwich,
australia, Paris or Gâtineau ? Who does it, the Puppy-builder ?
I think the top Puppy Builder at the woof-CE level sets the time for his Time
Zone. The user has to change it to his.
Pelo wrote:First settings : if i choose Paris, time 18:44 is wrong, it's 16:44 (untick UTC ,
then good)old how-to topic
Yes, that's a good way of doing it manually.

Code: Select all

htpdate -s [a web site in your country]
or

Code: Select all

ntpdate pool.ntp.org 
(if 'pool.ntp.org' is properly configured for your country), will do it
automatically for you.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

hamoudoudou

Puduan by Sailor eceladus a a gui appearing to click on to a

#15 Post by hamoudoudou »

Puduan by Sailor enceladus a a gui appearing to click on to adjust time.. But it does not work. Wen time is in the past i don't mind, i have clocks on the wall

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#16 Post by musher0 »

Hello all.

Please find attached as a pet the htpdate utility compiled for the most
recent slacko-700 and ScPup-19.01
(at the time of this writing).

It may or may not be suited for other Pups, since this exec requires
GNU libc version 2.28 to work. Please check the ldd version in your Pup,
like so: open a console and type in it:

Code: Select all

ldd --version
It will tell you.

I tested it thoroughly (I think), but use at your own peril, as usual.
Please take a minute to read the NOTE in the script below and call the
htpdate man page if you need more info. Or leave your question below.

Enjoy.

~~~~~~~~~~~~

Code: Select all

#!/bin/bash
MBINS=/root/my-applications/bin
[ ! -d $MBINS ] && MBINS=/opt/local/bin
# $MBINS/htpdate.sh
# With link in: / Avec lien dans : /root/Startup
#
# Goal: Synchronise the time and date of your Puppy with Internet
# ----- time by probing various http sites.
#
# Objectif : Synchroniser le temps et l'heure de votre Toutou ou 
# ---------- Puppy en sondant divers sites http.
#
# Please read the NOTE below. / S.v.p. lire la NOTE ci-dessous.
#
# (c) musher0, Gatineau (Qc), Canada, 27 décembre 2018. GPL3.
####
[ -f /root/root/last-date ] && date --set="`cat /root/last-date`" || date --set="20181227 14:28"
sleep 2s

htpdate -as www.linux.org www.freebsd.org www.ask.com unix.stackexchange.com puppylinux.com www.gnu.org www.cnrs.fr www.assnat.qc.ca www.parl.ca

date > /root/last-date

exit

~~~~~~~~~~~~~~
~~ NOTE ~~
~~~~~~~~~~~
Replaces /usr/local/ptimesync and /root/Startup/timesync.sh
(please remove or store out of the way) in slacko-700_32-bits. 

As it is, this script should offer a precision between 0.6 and
0.167 of a second.

If you wish, you can test and use other public sites than 
those above.

~~~~~~~~~~~~~~

Remplace /usr/local/ptimesync et /root/Startup/timesync.sh
(s.v.p. enlever ou entreproser ailleurs) dans slacko-700_32-bits.

Tel quel, le script devrait offrir une précision de 0,6 à 0,167
seconde.

Si vous le souhaitez, vous pouvez tester et utiliser d'autres
sites publics que ceux ci-dessus.
~~~~~~~~~~~~~~
In the picture below
-- the first line is the command itself;
-- the second line is the date and time in file "last-date";
-- the third line is the update from "last-date";
-- the fourth line is the new current time and date.

AFAICT, htpdate gives an error if you start it on a computer with a dead
battery. Please correct me if I'm wrong, but htpdate does not seem to be
able to recognize old dates such as "Jan. 3 1980, 00:01 hr".

As a workaround, I devised the following:
The fictitious relatively recent date contained in file "last-date" is fed into
the OS by command < date --set="`cat /root/last-date`" >. If file
"last-date" does not exist it is created. Then htpdate updates from that
time and date. That way, it's easier on the girl! ;)

IHTH.
Attachments
Running-htpdate.sh.jpg
Running htpdate.sh in console will give you something like this.
(18.23 KiB) Downloaded 662 times
htpdate-master-181227.pet
(10.02 KiB) Downloaded 392 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#17 Post by musher0 »

Hello all.

Please find attached an update.

Useful info, I think, from the newly edited script.
# Required: htpdate (in the pet archive containing this script)
# --------- hwclock, grep (already in your Pup).
(...)
# The hwclock "check and set" at lines 17 and 28 was needed
# to allow setting the time for the user's entire session.
(...)

# As it is, this script should offer a precision between 0.6 and
# 0.167 of a second.

# I am using the sites of the Parliament of Canada and of Québec's
# National Assembly among other time servers. If checking those sites
# takes too much time because they are too far away, please feel free to
# test and incorporate in the htpdate URL series above other public or
# governmental sites closer to your location.

# This script should prove useful if your computer battery is dead.
The major change in this version is the use of hwclock to introduce some
permanence of the time data at the HW level for your entire session. This
means that htpdate works only once, at the beginning of your session.

Should you change WM's, say, during your session, or temporarily go to the
initial black console to check something, and then come back in X, the time
data will have been preserved. The time in your task bar or in your analog
clock if you have one, should follow the natural increment for the duration.

When you relaunch a session the next day, later in the day, or some other
day, the script will find a mini file with the previous day's time data in it, so
htpdate does not have to figure out the present time starting from zilch. At
boot, a discrepancy will show in your computer clocks, but it will correct
itself automatically after approx. a minute. During the rest of your session,
this script should now offer "smooth sailing".

If the above is not clear, please leave your question below. Comments and
try-out reports also welcome.

Enjoy.
Attachments
htpdate-0.2.pet
(12.65 KiB) Downloaded 354 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#18 Post by musher0 »

Hello again, all.

I continued testing with htpdate, and this version of the script seems
to work the best. Please ditch any previous version.

I moved the script to /etc/init.d, under the filename start_
htpdate-0.3.sh and removed the symlink in /root/Startup.

Scripts in /etc/init.d with the 'start' prefix are run before the ones in
/root/Startup. This gives the script more time to establish the system
time and date, with the added benefit that there is less of a bottleneck
in /root/Startup at boot time.

I reworded the NOTE to include a solution if the script seems to jam
after a power outage or something as drastic.
Please make a mental
note. It is:
# IMPORTANT: After a power outage or any sudden break of the OS,
# this script may fail. To restore normal operation, open a console in
# /root/my-applications/bin and type, exactly:
# `grep htpdate htpdate-0.3.sh | grep -v "#"`
# rerun this script and then reboot.
Unless i get some problematic feedback for you guys, I think this will be
the last version.

Enjoy.
Attachments
htpdate-0.3a.pet
This is potentially the last version, so please remove any previous one.
(15.44 KiB) Downloaded 362 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
gychang
Posts: 414
Joined: Sat 29 Nov 2008, 20:30
Location: San Diego, CA

Re: How to set time

#19 Post by gychang »

labbe5 wrote:In Trinitydog :

First, i installed ntp.
Then i added ca.pool.ntp.org in /etc/systemd/timesyncd.conf.

The file looks like this :

[Time]
NTP=ca.pool.ntp.org #nearest server for me

Testing in terminal :
timedatectl status

Resulting values :
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no

Finally, reboot.
Now time should be correct.

In Stretchdog with Openbox (from mklive-stretch script & default config)

An alternative way of setting system time.

UTC is used, and there is a mismatch between UTC and local time.

To set the time :
# date -s hh:mm:ss #in Conky, UTC is now set to local time
To set the hardware clock :
# hwclock --systohc --utc

Now local time is ok and is set persistently.

Website of interest related to time zones : http://www.timebie.com/std/edt.php?q=15.5

Further reading :
http://www.putorius.net/2015/04/setting ... hat-7.html
If you are getting wrong time with the USA pacific zone, make sure on initial quick setup screen set "America_Los_Angeles" NOT "US/Pacific*" does not keep proper time.

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#20 Post by fredx181 »

I use this for to geolocate timezone (will set the timezone automatically, according to where you are):
https://github.com/cdown/tzupdate
But note that python is required to have installed.
Just downloaded tzupdate.py :
https://github.com/cdown/tzupdate/raw/d ... zupdate.py
(right click > Save link as)
Put it in /usr/local/bin and make executable:

Code: Select all

chmod +x /usr/local/bin/tzupdate.py
Then create bash script that runs tzupdate.py followed by ntpdate :

Code: Select all

/usr/local/bin/tzupdate.py
sleep 1
ntpdate -s ntp.ubuntu.com
There must be a working network connection before running this.
Best is to let it scan for connection first, so then becomes like this:

Code: Select all

#!/bin/bash
check_network () {
busybox ping -c1 duckduckgo.com 2> /dev/null
    if [[ $? -ne 0 ]]; then
echo "No network connection yet..."
fi

while true
do
busybox ping -c1 duckduckgo.com 2> /dev/null
    if [[ $? -eq 0 ]]; then
echo "Connected"
break
    fi
    sleep 2
done
}
export -f check_network

/bin/bash -c check_network

/usr/local/bin/tzupdate.py
sleep 1
ntpdate -s ntp.ubuntu.com
-----------------------------------------------

Probably similar thing (to get your timezone) can be done without python, just bash, e.g. :

Code: Select all

curl --request GET \
  --url https://freegeoip.app/json/ \
  --header 'accept: application/json' \
  --header 'content-type: application/json'
And then extract the timezone from the output.
EDIT: This should do to extract:

Code: Select all

TZ=$(curl -s --request GET --url https://freegeoip.app/json/ --header 'accept: application/json' --header 'content-type: application/json' | tr ',' '\n' | grep "time_zone" | cut -d ":" -f2|sed s'/.$//;s/"//')
echo $TZ         # display timezone
Fred

Post Reply