Convert between date and unix timestamp: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
mNo edit summary
Line 28: Line 28:
{{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 1900/1/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}}
{{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 1900/1/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]
PHP way: convert to date from unix timestamp
<pre>
<pre>
// timestamp: 1552521600
// timestamp: 1552521600
Line 41: Line 36:
// Thursday, 14-Mar-19 00:00:00 UTC in RFC 2822
// Thursday, 14-Mar-19 00:00:00 UTC in RFC 2822
// 2019-03-14T00:00:00+00:00 in RFC 3339
// 2019-03-14T00:00:00+00:00 in RFC 3339
</pre>
== Convert between date and unix timestamp ==


Online tool
* {{Gd}} [https://www.unixtimestamp.com/index.php Unix Time Stamp - Epoch Converter]
=== PHP way: convert to date time from unix timestamp ===
<pre>
date_default_timezone_set("Europe/London");
date_default_timezone_set("Europe/London");
$timestamp = 1552521600;
$timestamp = 1552521600;
Line 51: Line 55:
</pre>
</pre>


Excel way: convert to date from unix timestamp
 
=== PHP way: convert to unix timestamp from  date time ===
<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://www.extendoffice.com/documents/excel/2473-excel-timestamp-to-date.html How to convert between date and Unix timestamp in Excel?]
* [https://www.extendoffice.com/documents/excel/2473-excel-timestamp-to-date.html How to convert between date and Unix timestamp in Excel?]
* [https://docs.google.com/spreadsheets/d/1mUPLWLdCHcN5Nr3CL2JWYfdYmy4JyiYClXD1kHMLZc4/edit?usp=sharing demo]
* [https://docs.google.com/spreadsheets/d/1mUPLWLdCHcN5Nr3CL2JWYfdYmy4JyiYClXD1kHMLZc4/edit?usp=sharing demo]

Revision as of 00:44, 25 July 2019

terms of time format

format \ date 1900/1/1 1970/1/1 2016/1/1 notes
value of unix timestamp
(the number of seconds since 1970/01/01[1])
-2209075200 0 1451606400
value of Excel DATEVALUE function
(Excel: number of days since 1900/1/1)
1 25569 42370 5 digit numbers after 1970/1/1

Icon_exclaim.gif VALUE() function on Excel is number of days since 1900/1/1. VALUE() function on Google sheet is number of days since 1899/12/30 [Last visited: 2019-05-22]

// 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

Convert between date and unix timestamp

Online tool


PHP way: convert to date time from unix timestamp

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


PHP way: convert to unix timestamp from date time

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

Excel way: convert to date from unix timestamp

References