utc class atrribute of timezone class

The class atrribute utc returns a timezone instance corresponding the UTC. In the returned instance, the offset is zero and the name is UTC.

Timezone Updated 20 Aug 2021 1 min read

Overview

  • The class atrribute utc returns a timezone object which has the offset and name set for the UTC.

Example

python
# Example Python program that gets the

            # timezone object of UTC from the timezone class attribute

            # timezone.utc

            from datetime import timedelta, timezone, time

# Get the UTC timezone object

            utc = timezone.utc

# Get the offset

            offset = utc.utcoffset(None)

# Get the name

            name = utc.tzname(None)

# Print UTC information

            print(name)

            print(offset)

            print(type(utc))

Output

Output
UTC

0:00:00

<class 'datetime.timezone'>