当前位置:网站首页>php中时间戳转换为毫秒以及格式化时间
php中时间戳转换为毫秒以及格式化时间
2022-07-02 06:23:00 【夜空の雪風】
前言
有时候需要对时间戳进行操作,比如获取13位毫秒级的时间戳或者对时间戳进行格式化时间。
/** * 转化时间为毫秒时间戳 * @param int|string $time 时间戳|日期 * @return int */
function get_time($time)
{
if (is_numeric($time)) {
return (int) str_pad($time, 13, "0", STR_PAD_RIGHT);
} else {
return strtotime($time) * 1000;
}
}
/** * 时间戳转化为日期 * @param int|string $time 时间戳|日期 * @param string $format 格式化方式 * @return string */
function time_format($time, $format = 'Y-m-d')
{
if (is_numeric($time)) {
return date($format, substr($time, 0, 10));
} else {
return $time;
}
}
边栏推荐
- 浏览器滚动加载更多实现
- [self cultivation of programmers] - Reflection on job hunting Part II
- CVE-2015-1635(MS15-034 )远程代码执行漏洞复现
- [daily question] - Huawei machine test 01
- CVE-2015-1635(MS15-034 )遠程代碼執行漏洞複現
- SQLI-LABS通关(less15-less17)
- Win10:添加或者删除开机启动项,在开机启动项中添加在用户自定义的启动文件
- ZZQ的博客目录--更新于20210601
- Redis -- cache breakdown, penetration, avalanche
- 20201025 visual studio2019 qt5.14 use of signal and slot functions
猜你喜欢
Sqli-labs customs clearance (less18-less20)
sqli-labs通关汇总-page1
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
Uniapp introduces local fonts
PHP Session原理简析
Implement strstr() II
默认google浏览器打不开链接(点击超链接没有反应)
Cve - 2015 - 1635 (ms15 - 034) réplication de la vulnérabilité d'exécution de code à distance
UEditor .Net版本任意文件上传漏洞复现
Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决
随机推荐
PIP install
Self cultivation of programmers - Reflection on job hunting
Tool grass welfare post
AWD learning
Date time API details
Linux MySQL 5.6.51 Community Generic 安装教程
How to try catch statements that return promise objects in JS
解决微信小程序swiper组件bindchange事件抖动问题
js中map和forEach的用法
Huawei mindspire open source internship machine test questions
Fe - eggjs combined with typeorm cannot connect to the database
Sqli - Labs Clearance (less6 - less14)
Eggjs -typeorm treeenity practice
Flask migrate cannot detect db String() equal length change
Differences between ts and JS
No process runs when querying GPU, but the video memory is occupied
Self study table Au
js删除字符串的最后一位
Browser scrolling for more implementations
PHP Session原理简析