Converting epoch number to human readable date in mysql

Your epoch value 1389422614485 seems like having the millisecond precision. So you need to use some mysql mathematical functions along with from_unixtime() for generating human readable format. mysql> select from_unixtime(floor(1389422614485/1000)); +——————————————+ | from_unixtime(floor(1389422614485/1000)) | +——————————————+ | 2014-01-11 12:13:34 | +——————————————+ Update July 2020: As of MySQL 8.0, the floor function is no longer necessary when …

Read more

Convert a column of datetimes to epoch in Python

convert the string to a datetime using to_datetime and then subtract datetime 1970-1-1 and call dt.total_seconds(): In [2]: import pandas as pd import datetime as dt df = pd.DataFrame({‘date’:[‘2011-04-24 01:30:00.000’]}) df Out[2]: date 0 2011-04-24 01:30:00.000 In [3]: df[‘date’] = pd.to_datetime(df[‘date’]) df Out[3]: date 0 2011-04-24 01:30:00 In [6]: (df[‘date’] – dt.datetime(1970,1,1)).dt.total_seconds() Out[6]: 0 1303608600 …

Read more

Use Moment.js to convert Unix epoch time to human readable time

You can initialize a moment object with the unix timestamp and then use the format() function to get your desired output. const yourUnixEpochTime = 1687340912000; // Create moment object from epoch and convert to format: const formattedTime = moment(yourUnixEpochTime).format(“dddd, MMMM Do, YYYY h:mm A”) $(“#time”).text(formattedTime); <script src=”https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> <script src=”https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js”></script> <p id=”time”></p>

Is a day always 86,400 epoch seconds long?

Whenever doing calendrical calculations, it is almost always better to use whatever API the platform provides, such as Python’s datetime and calendar modules, or a mature high-quality library, than it is to write “simpler” code yourself. Date and calendar APIs are ugly and complicated, but that’s because real-world calendars have a lot of weird behavior. …

Read more