Time

Time allows working with time, dates and performance measurements.

Create Time objects#

ConstructorDescription
Time.now()Current local time
Time.from_timestamp(s)From UNIX seconds
Time.from_date(y, m, d)From specific date
Local time

By default, now() uses the system’s time zone. It is not necessary to specify it or perform conversions.

Current time#

now = Time.now()
print now.year
print now.month
print now.day

From UNIX timestamp#

date = Time.from_timestamp(1735689600)
print date.year  # 2025

From specific date#

christmas = Time.from_date(2025 12 25)
print christmas.month  # 12

Read properties#

PropertyDescription
time.yearYear
time.monthMonth (1-12)
time.dayDay
time.hourHour (0-23)
time.minuteMinute (0-59)
time.secondSecond (0-59)
time.timestampUNIX seconds
now = Time.now()
print now.year      # Year
print now.month     # Month (1-12)
print now.day       # Day
print now.hour      # Hour (0-23)
print now.minute    # Minute (0-59)
print now.second    # Second (0-59)
print now.timestamp # Seconds since UNIX EPOCH

Format dates#

MethodDescription
time.format()Default format
time.format(p)Custom format

Default format#

now = Time.now()
print now.format()  # YYYY-MM-DD HH:MM:SS

Custom format#

FormatDescription
%YYear
%mMonth
%dDay
%HHour
%MMinute
%SSecond
now = Time.now()
print now.format("%d/%m/%Y")
print now.format("%H:%M")

Time operations#

MethodDescription
time.add_seconds(n)Add seconds

Add seconds#

now = Time.now()
future = now.add_seconds(3600)
print future.hour  # One hour later

Pauses and measurement#

MethodDescription
Time.sleep(n)Pause execution
Time.perf_counter()Measure performance

Pause execution#

Time.sleep 2     # 2 seconds
Time.sleep 0.5   # 0.5 seconds

Measure performance#

start = Time.perf_counter()
# ... code ...
end = Time.perf_counter()
duration = end - start
print "It took " duration " seconds."