Editing
Convert between date and unix timestamp
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== terms of time format === <div style="width:100%; min-height: .01%; overflow-x: auto;"> <table border="1" class="wikitable sortable nowrap"> <tr> <th> format \ date </th> <th> 1899/12/31 (1900/1/0)</th> <th> 1900/1/1</th> <th> 1970/1/1</th> <th> 2016/1/1 </th> <th> notes </th> </tr> <tr> <td> value of unix timestamp <br /> (the number of seconds since 1970/01/01<ref>[https://www.extendoffice.com/documents/excel/2473-excel-timestamp-to-date.html How to convert between date and Unix timestamp in Excel?]</ref>)</td> <td> -2209075200</td> <td> -2208988800</td> <td> 0</td> <td> 1451606400</td> <td> </td> </tr> <tr> <td> value of Excel [https://support.office.com/zh-tw/article/DATEVALUE-%E5%87%BD%E6%95%B8-df8b07d4-7761-4a93-bc33-b7471bbff252 DATEVALUE] function or LibreOffice [https://help.libreoffice.org/Calc/DATEVALUE/zh-TW DATEVALUE] function<br /> (Excel: number of days since 1898/12/31) </td> <td> 0</td> <td> 1</td> <td> 25569</td> <td> 42370</td> <td> 5 digit numbers after 1970/1/1 </td> </tr> </table> </div> {{exclaim}} [https://support.office.com/zh-tw/article/value-%E5%87%BD%E6%95%B8-257d0108-07dc-437d-ae1c-bc2d3953d8c2 VALUE()] function on Excel is number of days since 1899/12/31. DATEVALUE of 1900/1/1 will return 1. [https://support.google.com/docs/answer/3094220?hl=en VALUE()] function on Google sheet is number of days since 1899/12/30 {{access | date=2019-05-22}} == Convert between date and unix timestamp == Online tool * {{Gd}} [https://www.unixtimestamp.com/index.php Unix Time Stamp - Epoch Converter] <pre> // timestamp: 1552521600 // Is equivalent to: // 03/14/2019 @ 12:00am (UTC) // 2019-03-14T00:00:00+00:00 in ISO 8601 // Thu, 14 Mar 2019 00:00:00 +0000 in RFC 822, 1036, 1123, 2822 // Thursday, 14-Mar-19 00:00:00 UTC in RFC 2822 // 2019-03-14T00:00:00+00:00 in RFC 3339 </pre> === PHP way: convert to date time from unix timestamp === Using the [https://www.php.net/manual/en/function.date.php date()] function & [https://www.php.net/manual/en/function.date-default-timezone-set.php date_default_timezone_set] <pre> date_default_timezone_set('UTC'); $timestamp = 0; echo date('Y-m-d H:i:s', $timestamp) . PHP_EOL; // 1970-01-01 00:00:00 date_default_timezone_set("Europe/London"); $timestamp = 1552521600; echo date('Y-m-d H:i:s', $timestamp) . PHP_EOL; // 2019-03-14 00:00:00 date_default_timezone_set("Asia/Taipei"); $timestamp = 1552521600; echo date('Y-m-d H:i:s', $timestamp) . PHP_EOL; // 2019-03-14 08:00:00 </pre> === PHP way: convert to unix timestamp from date time === Using the [https://www.php.net/manual/en/function.strtotime.php strtotime()] function <pre> date_default_timezone_set("Europe/London"); echo strtotime('2019-03-14 00:00:00') . PHP_EOL; // 1552521600 date_default_timezone_set("Asia/Taipei"); echo strtotime('2019-03-14 08:00:00') . PHP_EOL; // 1552521600 </pre> === Excel way: convert to date from unix timestamp === * [https://errerrors.blogspot.com/2019/09/how-to-convert-between-date-and-unix-timestamp-in-excel.html 怎樣轉換 Excel 日期時間成 Unix 時間戳記 (unix timestamp)] * [https://www.extendoffice.com/documents/excel/2473-excel-timestamp-to-date.html How to convert between date and Unix timestamp in Excel?] timezone: UTC <pre> = (VALUE( date_time )-25569)*86400 </pre> === Excel way: convert to unix timestamp from date === input data (A2 cell): YYYY/MM/DD (e.g. {{CURRENTYEAR}}/{{CURRENTMONTH}}/{{CURRENTDAY2}} ) or YYYY/MM/DD HH:MM (e.g. {{CURRENTYEAR}}/{{CURRENTMONTH}}/{{CURRENTDAY2}} {{CURRENTTIME}}) {{kbd | key==(A2-DATE(1970,1,1))*86400}} <ref>[http://stackoverflow.com/questions/1703505/excel-date-to-unix-timestamp Excel date to Unix timestamp - Stack Overflow]</ref> timezone: UTC <pre> = TEXT( (Unixtime / 86400) + 25569, "YYYY-mm-dd hh:mm:ss") </pre> === MySQL way: convert to date from unix timestamp === timezone: MySQL server timezone dependent {{exclaim}}<ref>[https://www.w3resource.com/mysql/date-and-time-functions/mysql-from_unixtime-function.php MySQL FROM_UNIXTIME() function]</ref> <pre> SELECT FROM_UNIXTIME(IF(`timestamp_column` = 0, NULL, `timestamp_column`, "%Y-%m-%d %H:%i:%S") </pre> === MySQL way: convert to unix timestamp from date time === Using [https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_unix-timestamp UNIX_TIMESTAMP()] function timezone: MySQL server timezone dependent {{exclaim}} * {{kbd | key = SELECT UNIX_TIMESTAMP('2011-03-15 18:53:57');}} /* return timestamp: 1300186437 */ * {{kbd | key = SELECT UNIX_TIMESTAMP(STR_TO_DATE('2011-03-15 18:53:57', '%Y-%m-%d %H:%i:%S'));}} /* return timestamp: 1300186437 */ == References == <references /> {{Template:Data factory flow}} [[Category:PHP]] [[Category:Programming]] [[Category:Web_Dev]] [[Category:MySQL]] [[Category:Excel]] [[Category:Data Science]] [[Category:Time river]]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Access
(
view source
) (protected)
Template:Data factory flow
(
edit
)
Template:Exclaim
(
edit
)
Template:Gd
(
edit
)
Template:Kbd
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information