Python Pendulum Properties and Duration Methods 2














































Python Pendulum Properties and Duration Methods 2



             Properties and duration methods 


 If you want to get the duration in each supported unit you can use the appropriate methods.

import pendulum

it = pendulum.duration(
years=2, months=3,
days=1177, seconds=7284, microseconds=1234
)
# Each method returns a float like the native
# total_seconds() method
print(it.total_weeks())
print(it.total_days())
print(it.total_hours())
print(it.total_minutes())
print(it.total_seconds())


     #OUTPUT

285.2977579385483
1997.0843055698379
47930.02333367611
2875801.400020567
172548084.001234


 Similarly, the in_xxx() methods return the total duration in each supported unit as a truncated integer.


print(it.in_weeks())
print(it.in_days())
print(it.in_hours())
print(it.in_minutes())
print(it.in_seconds())


    #OUTPUT

285
1997
47930
2875801
172548084


 It also has a handy in_words() method, which determines the duration representation when printed.


import pendulum
pendulum.set_locale('en')
it = pendulum.duration(days=1177, seconds=7284, microseconds=1234)
print(it.in_words())
print(it)
print(it.in_words(locale='de')) #in spanish



     #OUTPUT


168 weeks 1 day 2 hours 1 minute 24 seconds
168 weeks 1 day 2 hours 1 minute 24 seconds
168 Wochen 1 Tag 2 Stunden 1 Minute 24 Sekunden



More Articles of Anmol Agrawal:

Name Views Likes
Python Pendulum Why to use Pendulum 81 0
Python Pendulum Limitations in DJANGO 115 0
Python Pendulum Limitations in MYSQLCLIENT 91 0
Python Pendulum Limitations in SQLITE3 95 0
Python Pendulum Testing 2 100 0
Python Pendulum Testing 113 0
Python Pendulum Range 110 0
Python Pendulum Period 3 108 0
Python Pendulum Period 2 103 0
Python Pendulum Period 100 0
Python Pendulum Properties and Duration Methods 2 98 0
Python Pendulum Properties and Duration Methods 106 0
Python Pendulum Instantiation 107 0
Python Pendulum Duration 104 0
Python Pendulum TImezone usage 2 94 0
Python Pendulum Timezone usage 93 0
Python Pendulum Switching Timezones 100 0
Python Pendulum Shifting Time to Transition 112 0
Python Pendulum Normalization 109 0
Python Pendulum Modifiers 2 110 0
Python Pendulum Modifiers 106 0
Python Pendulum Difference for Humans 2 141 0
Python Pendulum Difference for Humans 113 0
Python Pendulum Difference 115 0
Python pendulum Substraction 127 0
Pyhton pendulum Addition 123 0
Python pendulum Comapaison part 2 116 0
Python Pendulum Comparison 118 0
Python Pendulum Localized Formats and Escaping characteristics 117 0
Python pendulum Tokens 124 0
Python pendulum Formatter 116 0
Python pendulum Common Formats 122 0
Python pendulum String Formatting 123 0
Python pendulum Fluent helpers 2 116 0
Python pendulum Fluent helpers 105 0
Python pendulum Attributes and Properties 111 0
Python pendulum Localization 135 118
Python pendulum parsing 2 130 23
Python pendulum Parsing 1 137 61
Python pendulum 2 145 57
Python pendulum basics 136 9
python library Pendulum 136 33
python winsound.SND_PURGE and winsound.SND_WAIT 149 5
Python winsound.SND_NOSTOP 178 1
Python winsound.SND_NODEFAULT 158 1
python winsound.SND_ASYNC not excecuting problem 164 2
Python winsound functions 181 3
python winsound.SND_ALIAS 190 1
Python winsound.MessageBeep() 205 1
Python winsound basic introduction 241 1

Comments