Skip to content

Instantly share code, notes, and snippets.

@WenLiangTseng
Created July 22, 2013 13:13
Show Gist options
  • Save WenLiangTseng/6053717 to your computer and use it in GitHub Desktop.
Save WenLiangTseng/6053717 to your computer and use it in GitHub Desktop.
PHP 將資料庫的 timestamp 轉換成其他的日期格式(如年/月/日)
<?php
//$timestamp = $row->date; // get your timestamp data from MySQL database's table field.
$timestamp = "2008-10-05 21:34:02";
echo date("Y/n/d", strtotime( $timestamp ));
//other examples:
echo date("F j, Y g:i a", strtotime( $timestamp )); // October 5, 2008 9:34 pm
echo date("m.d.y", strtotime( $timestamp )); // 10.05.08
echo date("j, n, Y", strtotime( $timestamp )); // 5, 10, 2008
echo date("Ymd", strtotime( $timestamp )); // 20081005
echo date('\i\t \i\s \t\h\e jS \d\a\y.', strtotime( $timestamp )); // It is the 5th day.
echo date("D M j G:i:s T Y", strtotime( $timestamp )); // Sun Oct 5 21:34:02 PST 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment