如何创建人类可读的时间戳? [英] How to create human readable time stamp?

查看:88
本文介绍了如何创建人类可读的时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我当前的PHP程序:

This is my current PHP program:

$dateStamp = $_SERVER['REQUEST_TIME'];

我稍后登录.

结果是$dateStamp变量包含数字,例如:

The result is that the $dateStamp variable contains numbers like:

1385615749

1385615749

这是Unix时间戳,但是我希望它包含人类可读的日期,包括小时,分钟,秒,日期,月份和年份.

This is a Unix timestamp, but I want it to contain human readable date with hour, minutes, seconds, date, months, and years.

所以我需要一个将其转换为人类可读日期的函数.

So I need a function that will convert it into a human readable date.

我该怎么做?

还有其他类似的问题,但并非如此.我想要最简单的解决方案.

There are other similar questions but not quite like this. I want the simplest possible solution.

推荐答案

该数字称为 Unix时间.诸如 date() 之类的函数可以接受它作为可选的第二个参数,以在可读的时间内对其进行格式化.

This number is called Unix time. Functions like date() can accept it as the optional second parameter to format it in readable time.

示例:

echo date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']);

如果省略第二个参数,将使用 time() 的当前值.

If you omit the second parameter the current value of time() will be used.

echo date('Y-m-d H:i:s');

这篇关于如何创建人类可读的时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆