Python pendulum 2














































Python pendulum 2



 In the previous article, we have seen how to implement pendulum basic functions.Now we see how to convert timezones using pendulum library.

We can convert timezones using in_timezone() function.UTC(Coordinated Universal Time) is the primary time standard by which the world regulates clocks and time.


    #Code
    # Importing library
    import pendulum

    # Getting current UTC time
    utc_time = pendulum.now('UTC')

   # Switching current timezone to
   # Kolkata timezone using in_timezone().
   kolkata_time = utc_time.in_timezone('Asia/Kolkata')
   print('Current Date Time in Kolkata =', kolkata_time)

   # Generating Sydney timezone
   sydney_tz = pendulum.timezone('Australia/Sydney')

   # Switching current timezone to
   # Sydney timezone using convert().
    sydney_time = sydney_tz.convert(utc_time)
    print('Current Date Time in Sydney =', sydney_time)



    #OUTPUT
    Current Date Time in Kolkata = 2022-06-27T21:29:47.075713+05:30
    Current Date Time in Sydney = 2022-06-28T01:59:47.075713+10:00


Date Time Manipulations

    For date-time manipulation, we can use the add() and subtract() methods. Each method returns a new   DateTime instance.


    #Code

    # Importing the library
    import pendulum
    # creating datetime instance
    dt = pendulum.datetime(2022, 6, 27)
    print(dt)

    # Manipulating datetime object using add()
    dt = dt.add(years=5)
    print(dt)

    # Manipulating datetime object using subtract()
    dt = dt.subtract(months = 1)
    print(dt)

    # Similarly we can add or subtract months,weeks,days,hours,minutes
    # individually or all at a time.
    dt = dt.add(years=3, months=2, days=6,hours=12, minutes=30, seconds=45)

    print(dt)

    #OUTPUT

2022-06-27T00:00:00+00:00
2027-06-27T00:00:00+00:00
2027-05-27T00:00:00+00:00
2030-08-02T12:30:45+00:00

More Articles of Anmol Agrawal:

Name Views Likes
Python Pendulum Why to use Pendulum 69 0
Python Pendulum Limitations in DJANGO 95 0
Python Pendulum Limitations in MYSQLCLIENT 79 0
Python Pendulum Limitations in SQLITE3 80 0
Python Pendulum Testing 2 83 0
Python Pendulum Testing 100 0
Python Pendulum Range 97 0
Python Pendulum Period 3 95 0
Python Pendulum Period 2 92 0
Python Pendulum Period 88 0
Python Pendulum Properties and Duration Methods 2 88 0
Python Pendulum Properties and Duration Methods 93 0
Python Pendulum Instantiation 93 0
Python Pendulum Duration 90 0
Python Pendulum TImezone usage 2 81 0
Python Pendulum Timezone usage 80 0
Python Pendulum Switching Timezones 86 0
Python Pendulum Shifting Time to Transition 97 0
Python Pendulum Normalization 96 0
Python Pendulum Modifiers 2 98 0
Python Pendulum Modifiers 95 0
Python Pendulum Difference for Humans 2 130 0
Python Pendulum Difference for Humans 100 0
Python Pendulum Difference 106 0
Python pendulum Substraction 114 0
Pyhton pendulum Addition 110 0
Python pendulum Comapaison part 2 103 0
Python Pendulum Comparison 107 0
Python Pendulum Localized Formats and Escaping characteristics 101 0
Python pendulum Tokens 110 0
Python pendulum Formatter 103 0
Python pendulum Common Formats 108 0
Python pendulum String Formatting 112 0
Python pendulum Fluent helpers 2 105 0
Python pendulum Fluent helpers 95 0
Python pendulum Attributes and Properties 99 0
Python pendulum Localization 123 118
Python pendulum parsing 2 118 23
Python pendulum Parsing 1 127 61
Python pendulum 2 130 57
Python pendulum basics 122 9
python library Pendulum 123 33
python winsound.SND_PURGE and winsound.SND_WAIT 138 5
Python winsound.SND_NOSTOP 157 1
Python winsound.SND_NODEFAULT 147 1
python winsound.SND_ASYNC not excecuting problem 150 2
Python winsound functions 169 3
python winsound.SND_ALIAS 179 1
Python winsound.MessageBeep() 186 1
Python winsound basic introduction 224 1

Comments