Python pendulum basics














































Python pendulum basics



 In the previous article we have seen the python library pendulum basic introduction and also talked about its basic functions. Now we will see the implementation of those functions.

    #CODE


    # import library
    import pendulum
    dt = pendulum.datetime(2020, 6, 24)
    print(dt)
    #local() creates datetime instance with local timezone
    local = pendulum.local(2020, 6,24)
    print(local)
    print(local.timezone.name)

    #OUTPUT


    2020-06-24T00:00:00+00:00
    2020-06-24T00:00:00+05:30
    Asia/Calcutta

   

  Code for Now() function


    #CODE   


    import pendulum
    now = pendulum.now()
    tz = pendulum.timezone('Europe/London
')
    now_in_london_tz = pendulum.now(tz)
    # or just pass the timezone as a string
    now_in_london_tz = pendulum.now('Europe/London
')
    print(now_in_london_tz.timezone_name)

    # or to create a date with a timezone of +1 to GMT
    # during DST then just pass an integer
    print(pendulum.now(1).timezone_name)

    #OUTPUT


    Europe/London
    +01:00


  The only thing to really notice here is that today(), tommorow() and yesterday() ,besides     behaving as expected all accept a timezone parameter and each has their time value set to   00:00:00


    #Code

import pendulum

now = pendulum.now()
print(now)


today = pendulum.today()
print(today)


tomorrow = pendulum.tomorrow('Europe/London')
print(tomorrow)


yesterday = pendulum.yesterday()
print(yesterday)

    

    #OUTPUT

2022-06-26T00:09:44.111227+05:30

2022-06-26T00:00:00+05:30

2022-06-26T00:00:00+01:00

2022-06-25T00:00:00+05:30

 


More Articles of Anmol Agrawal:

Name Views Likes
Python Pendulum Why to use Pendulum 176 0
Python Pendulum Limitations in DJANGO 262 0
Python Pendulum Limitations in MYSQLCLIENT 182 0
Python Pendulum Limitations in SQLITE3 197 0
Python Pendulum Testing 2 182 0
Python Pendulum Testing 215 0
Python Pendulum Range 220 0
Python Pendulum Period 3 185 0
Python Pendulum Period 2 184 0
Python Pendulum Period 187 0
Python Pendulum Properties and Duration Methods 2 185 0
Python Pendulum Properties and Duration Methods 187 0
Python Pendulum Instantiation 185 0
Python Pendulum Duration 169 0
Python Pendulum TImezone usage 2 180 0
Python Pendulum Timezone usage 191 0
Python Pendulum Switching Timezones 177 0
Python Pendulum Shifting Time to Transition 207 0
Python Pendulum Normalization 192 0
Python Pendulum Modifiers 2 191 0
Python Pendulum Modifiers 190 0
Python Pendulum Difference for Humans 2 211 0
Python Pendulum Difference for Humans 230 0
Python Pendulum Difference 265 0
Python pendulum Substraction 209 0
Pyhton pendulum Addition 215 0
Python pendulum Comapaison part 2 209 0
Python Pendulum Comparison 217 0
Python Pendulum Localized Formats and Escaping characteristics 196 0
Python pendulum Tokens 198 0
Python pendulum Formatter 208 0
Python pendulum Common Formats 201 0
Python pendulum String Formatting 217 0
Python pendulum Fluent helpers 2 185 0
Python pendulum Fluent helpers 186 0
Python pendulum Attributes and Properties 218 0
Python pendulum Localization 230 118
Python pendulum parsing 2 221 23
Python pendulum Parsing 1 229 61
Python pendulum 2 247 57
Python pendulum basics 220 9
python library Pendulum 220 33
python winsound.SND_PURGE and winsound.SND_WAIT 263 5
Python winsound.SND_NOSTOP 276 1
Python winsound.SND_NODEFAULT 234 1
python winsound.SND_ASYNC not excecuting problem 244 2
Python winsound functions 295 3
python winsound.SND_ALIAS 286 1
Python winsound.MessageBeep() 449 1
Python winsound basic introduction 409 1

Comments