如何在PHP中获取当前日期+时间的人类可读字符串表示?

时间:2009-12-27 17:22:41

标签: php

它究竟是什么样子并不重要。我尝试创建一个错误日志类,需要在错误通知中打印一些有用的东西。对于需要修复错误的糟糕管理员来说,unix时间戳不会太明显;)

2 个答案:

答案 0 :(得分:3)

查看date功能

//assuming time() is exactly March 10, 2001, 5:16 pm

date("F j, Y, g:i a");
//prints March 10, 2001, 5:16 pm

date("d/m/y, H:i:s");
//prints 10/03/01 17:16:00

答案 1 :(得分:2)

来自docs

<?php
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('UTC');


// Prints something like: Monday
echo date("l");

// Prints something like: Monday 8th of August 2005 03:12:46 PM
echo date('l jS \of F Y h:i:s A');

// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));

/* use the constants in the format parameter */
// prints something like: Mon, 15 Aug 2005 15:12:46 UTC
echo date(DATE_RFC822);

// prints something like: 2000-07-01T00:00:00+00:00
echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));
?>