Python Forum
[SOLVED] Alternative to regex to extract date from whole timestamp?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] Alternative to regex to extract date from whole timestamp?
#2
I put this together, for my own reference, but if it's of help, then you're welcome to it.

import time

hr = '{}{}{}'.format('\n'*2,'-'*50,'\n') #horizontal rule

print('''time.gmtime(0): returns system’s epoch setting:
The starting point against which you can measure the
passage of time.
''')
system_epoch = time.gmtime()
print(system_epoch,hr)

print('''time.time() returns the number of seconds
that have passed since the epoch; return value is a
floating point number to account for fractional seconds:
''')
tt = time.time()
print(tt,hr)

print('''time.ctime() will return a string object
representation of the time and date based on the
number of seconds since epoch, or the current time
and date, if nothing is passed to the function.

The string representation of time, also known as a
timestamp, returned by ctime() is formatted with the
following structure:

    1: Day of the week
    2: Month of the year
    3: Day of the month
    4: Hours, minutes, and seconds using the 24-hour
       clock notation
    5: Year
''')
tc = time.ctime(1660867200)

print('''Note: time.ctime(0) may not return the same timestamp
on every computer system
''')

print('''For details about time zones, see:
https://realpython.com/python-time-module/
''')
print(tc,hr)
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Messages In This Thread
RE: Alternative to regex to extract date from whole timestamp? - by rob101 - Nov-16-2022, 10:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] [Windows] Change directory date? Winfried 2 414 May-11-2025, 04:24 PM
Last Post: Winfried
Question [SOLVED] Can't figure out right regex Winfried 3 706 Mar-02-2025, 05:57 PM
Last Post: Winfried
  Compare current date on calendar with date format file name Fioravanti 1 2,217 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Python date format changes to date & time 1418 4 2,901 Jan-20-2024, 04:45 AM
Last Post: 1418
  [solved] Regex expression do not want to taken :/ SpongeB0B 2 4,483 Nov-06-2023, 02:43 PM
Last Post: SpongeB0B
  Help with a regex? (solved) wrybread 3 1,621 May-01-2023, 05:12 AM
Last Post: deanhystad
  [SOLVED] [regex] Why isn't possible substring ignored? Winfried 4 2,222 Apr-08-2023, 06:36 PM
Last Post: Winfried
  [SOLVED] Epoch timestamp without milliseconds? Winfried 5 7,029 Jan-27-2023, 04:35 PM
Last Post: deanhystad
  error in timestamp Led_Zeppelin 3 5,084 Jun-15-2022, 08:28 PM
Last Post: deanhystad
  error in timestamp Led_Zeppelin 0 1,495 Jun-10-2022, 07:59 PM
Last Post: Led_Zeppelin

Forum Jump:

User Panel Messages

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