timedelta

Manipulating DateTime and TimeDelta objects in python

断了今生、忘了曾经 提交于 2019-12-08 01:26:55
问题 I am wondering how to manipulate Datetime and Time delta objects. I am writing a game where different planets have different timescales. And I was wondering how it might be possible to mod datetime objects. For example if I have a date time object - some past datetime object I was wondering if it was possible to know how many times 6 hours might into the different and what the remainder in minutes was? For example... now = datetime.now() then = some datetime object diff = now - then num 6

Pandas graphing a Timedelta series, with vertical lines at selected time

China☆狼群 提交于 2019-12-07 22:30:32
问题 I got a very similar question to this one : Pandas graphing a timeseries, with vertical lines at selected dates but the solution doesn't works with Timedelta. Consider this series: In: avg_hr.head() Out: 00:00:00 69.000000 00:00:01 93.750000 00:00:02 93.125000 00:00:03 92.900000 00:00:04 93.222222 00:00:05 93.222222 ... Name: bpm, Length: 253, dtype: float64 I can select element in this series like this: In: avg_hr[pd.Timedelta(seconds=3)] Out: 92.9 I can generate a graph like this: In: avg

Django DurationField default

岁酱吖の 提交于 2019-12-07 16:31:01
问题 I want to pass default value into DurationField from django 1.8. According to documentation it should be datetime.timedelta from datetime import timedelta pause = DurationField(default=timedelta(minutes=20)) But on makemigrations it says: ValueError: Cannot serialize: datetime.timedelta(0, 1200) There are some values Django cannot serialize into migration files. Ok. Maybe we should pass integer? pause = DurationField(default=int(timedelta(minutes=20).total_seconds())) or: pause =

Timedelta object cannot be converted with astype()

断了今生、忘了曾经 提交于 2019-12-07 04:09:53
问题 A native Pandas Timedelta() (with version 0.20.3 ), can't convert to a specific frequency with astype() , although the docs say it should be possible. I'm trying to figure out what I'm missing. From the Timedelta docs: Timedelta Series, TimedeltaIndex, and Timedelta scalars can be converted to other ‘frequencies’ by dividing by another timedelta, or by astyping to a specific timedelta type. It's true that I can convert by division with another timedelta: import pandas as pd pd.__version__ # 0

Number of seconds since the beginning of the day UTC timezone

点点圈 提交于 2019-12-06 20:58:05
问题 How do I find "number of seconds since the beginning of the day UTC timezone" in Python? I looked at the docs and didn't understand how to get this using datetime.timedelta . 回答1: Here's one way to do it. from datetime import datetime, time utcnow = datetime.utcnow() midnight_utc = datetime.combine(utcnow.date(), time(0)) delta = utcnow - midnight_utc print delta.seconds # <-- careful EDIT As suggested, if you want microsecond precision, or potentially crossing a 24-hour period (i.e. delta

need the average from a list of timedelta objects

☆樱花仙子☆ 提交于 2019-12-06 17:40:51
问题 I have created a list of timedelta objects and i need to get the average of this list. when i try to do return (sum(delta_list)/(len(delta_list)-1)) i get TypeError: unsupported operand type(s) for +: 'int' and 'datetime.timedelta' i am new at working with pythons datetime classes. I also would like to know how to get this average into a format like days: hours: mins: i don't need anything smaller than mins. 回答1: sum wants a starting value, which is 0 by default, but 0 can't be added to a

Displaying a timedelta object in a django template

故事扮演 提交于 2019-12-06 17:16:26
问题 I'm having trouble getting my django template to display a timedelta object consistently. I tried using the time filter in my template, but nothing is displayed when I do this. The timedelta object is shown as follows on the errors page if I use Assert False: time datetime.timedelta(0, 38, 132827) This displays the time difference as: 0:00:38.132827 I would like to only show the hours, minutes, and seconds for each timedelta object. Does anyone have any suggestions on how I can do this? 回答1:

Django DurationField default

自作多情 提交于 2019-12-05 20:22:16
I want to pass default value into DurationField from django 1.8. According to documentation it should be datetime.timedelta from datetime import timedelta pause = DurationField(default=timedelta(minutes=20)) But on makemigrations it says: ValueError: Cannot serialize: datetime.timedelta(0, 1200) There are some values Django cannot serialize into migration files. Ok. Maybe we should pass integer? pause = DurationField(default=int(timedelta(minutes=20).total_seconds())) or: pause = DurationField(default=20*60) makemigrations runs ok, but on object creation I see: for obj in self.query.objs File

Timedelta object cannot be converted with astype()

核能气质少年 提交于 2019-12-05 08:54:45
A native Pandas Timedelta() (with version 0.20.3 ), can't convert to a specific frequency with astype() , although the docs say it should be possible. I'm trying to figure out what I'm missing. From the Timedelta docs : Timedelta Series, TimedeltaIndex, and Timedelta scalars can be converted to other ‘frequencies’ by dividing by another timedelta, or by astyping to a specific timedelta type. It's true that I can convert by division with another timedelta: import pandas as pd pd.__version__ # 0.20.3 day = pd.Timedelta("1 day") day / pd.Timedelta(1, "h") # 24.0 But astype() fails: day.astype(

Android Studio Mediaplayer how to fade in and out

我与影子孤独终老i 提交于 2019-12-05 03:34:04
I am working with the mediaplayer class in android studio. I simply want to fade out one sound and fade in the other sound instead of using setVolume(0,0) and setVolume(1,1). I have created two mediaplayers for this and it seemed like I found a solution in this thread: Android: How to create fade-in/fade-out sound effects for any music file that my app plays? but I don't know how to use deltaTime. There are also some other solutions to this, which I can barely understand. Isn't there an easy way to cross fade two mediaplayers, I can not imagine no one has needed this yet or everyone uses