Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Written the Time...
#1
I looked google and seem not get what I wanted, so let I ask this...

what is the code that I can to WRITE the time into the system when network is offline?

I tried here:
import datetime
datetime.time(15, 8, 24) # 15:08:24
Looks like it did but the system did not save.
Reply
#2
this depends on where you want to write the time (such as a file or the console output or in a graphical window) and what format you want to write (names or numbers).  tell us more about what you are doing.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#3
Just Hour and Minute.

I am work on my project with time alarm.

when the Network is on and it will automatically setup current time.

when no network then have to setup time manually which is my issue can't to write set time into the Raspberry Pi 4B system.

When I press and hold on the touch screen then pop up new a window and change correct the time then click APPLY button are working but when I click "APPLY" and did not work to write the time into the system's real time.

I am using the Tkinter.

I just need the code anything to write time into the system I can figure out.

I see online: https://www.semicolonworld.com/question/...e-and-time
but they are using C language etc not what I want, I like use a simple for example   
 write.time("08:15") 
   that's it.
Reply
#4
like run on linux command:
date +%T -s "10:13:13"
Reply
#5
Why do you need to set the system time when you're offline? Surely it's set when you're online and it shouldn't be lost when you disconnect. Say more about what's actually going on.
Reply
#6
Python doesn't have anything in the standard library to set the time.  For a rpi, easiest would be to just call the system date command.

import os
mydate = "whatever the date should be"
os.system(f"date -s {mydate}")
Normal raspberry pi users don't have privileges to set the system time (python or no python).You would either have to:
  • Run the program as root
  • Run the program as a non-root user via sudo
  • Run the program as a non-root user with explicit privileges to set the date
The last is the "safest" (principle of least privilege), but would be the most difficult to set up if you're not already familiar with privileges.  If you're the only user, then running it as root/sudo shouldn't be a huge problem.
Reply
#7
(Oct-10-2020, 03:00 PM)ndc85430 Wrote: Why do you need to set the system time when you're offline? Surely it's set when you're online and it shouldn't be lost when you disconnect. Say more about what's actually going on.

Well, Can you say about power outage and no network? Big Grin

I wanted to do manually for plan B.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020