Seconds since epoch to relative date

2024/10/5 17:28:37

I'm working with dates since epoch, and already got, for example:

date = 6928727.56235

I'd like to transform this into another relative format, so that I'll be able to transform this into something relative to epoch.

Using time.gmtime(date), it returned

year=1970, mon=3, day=22, hour=4, min=38, sec=47

I think epoch starts in '01/01/1970 00:00:00', so the method should return the relative date in something like:

'2 months 21 days 04:38:47'

Anything that help?

Answer

The method should return the relativedate in something like:'2 months 22 days 04:38:47'

You can't do that, since a month is between 28 and 31 days long. The statement "2 months and 22 days" could mean anything between 81 and 84 days. (Or between 78 and 84 days, if the months doesn't have to be consecutive).

So what you want is simply nonsensical. A relative date time can only be counted in days, hours and seconds, until the difference becomes so big that the amount of days no longer matters, in which case you can start counting in months or years (but then you can't include days anymore).

So you can say "five years and two months", or "80 days and three hours", or "two hundred years". But you can not say "two months and three days" or "five years and 20 days". The statements simply make no sense.

Therefore, the correct answer is indeed eumiros

timedelta(seconds=6928727.56235)

But now you also know why.

(Unless of course, you with month actually mean moon-cycles, which do have a fixed length. :))

https://en.xdnf.cn/q/70464.html

Related Q&A

ring buffer with numpy/ctypes

Im developing a client which will receive the [EEG] data over tcp and write it to the ring buffer. I thought it can be very convenient to have the buffer as a ctypes or numpy array because its possible…

Get all available timezones

Im currently working on an application that is required to support multiple timezones.For that, Im using the dateutil library. Now, I need a way to present the user a list of all available timezones th…

Load blob image data into QPixmap

I am writing a program using PyQt4 for front-end GUI and this program accesses a back-end database (which can be either MySQL or SQLite). I need to store some image data in the database and below is th…

Fetch a value of SQLalchemy instrumentedattribute

How can I fetch the value of a InstrumentedAttribute object in SQLalchemy:(Pdb) ResultLine.item_reference_1 <sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x793dc90>The above statemen…

python super calling child methods

There are numerous questions on the usage of super() but none of them appears to answer my question. When calling super().__init__() from a subclass, all method calls in the super-constructor are actua…

How to create space between subplots? [duplicate]

This question already has answers here:Manipulation on vertical space in matplotlib subplots(3 answers)Closed 2 years ago.The title pretty much says it all. I have a notebook containing two subplots an…

How to (re)name an empty column header in a pandas dataframe without exporting to csv

I have a pandas dataframe df1 with an index column and an unnamed series of values. I want to assign a name to the unnamed series. The only way to do this that I know so far is to export to df1.csv usi…

Capturing the video stream from a website into a file

For my image classification project I need to collect classified images, and for me a good source would be different webcams around the world streaming video in the internet. Like this one:https://www.…

Recreating time series data using FFT results without using ifft

I analyzed the sunspots.dat data (below) using fft which is a classic example in this area. I obtained results from fft in real and imaginery parts. Then I tried to use these coefficients (first 20) to…

python BeautifulSoup get all href in Children of div

I am new to python and Ive been trying to get links and inner text from this html code : <div class="someclass"><ul class="listing"><li><a href="http://lin…