JavaScript前端将时间戳转换为日期格式
2024-10-16 19:06:33
function (data) {
var date = new Date(data)
var Y = date.getFullYear() + '-'
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())
return Y + M + D + h + m + s
}
参数data即为从后台或者其他地方传入的时间戳,最后转换的日期格式为:
如果需要其他格式,可以自行变化,如有疑问,可留言!
最新文章
- C#设计模式(2)——简单工厂模式
- Caf.CMS是一个免费的、 开源,功能齐全的CMS
- nodejs review-04
- SqlServer 递归查询树形数据
- 给input的按钮控件添加onserverclick事件
- Web服务器与Servlet容器
- kmeans理解
- ndk-gdb of NDK r9d modified to *always* debug the ";:remote";-process of your app
- JavaScript- The Good Parts function Curry
- bzoj3685普通van Emde Boas树 线段树
- MySQL常用命令(数据库,表相关的命令)
- python socket 实现的简单http服务器
- 洛谷P3354 Riv河流 [IOI2005] 树型dp
- Atitit 获取剪贴板内容
- javascript控制滚动条的位置,获取控件的位置
- hallo world
- Android filesystem system rw(read/write) permission
- jQuery的过滤器总结
- 在Ubuntu里启用root账号
- P1725 琪露诺
热门文章
- CSS之Flex 布局
- 基于jQuery日历插件制作日历
- MyEclipse打包带源码的jar包
- 命令行下运行 java someClass.class出现 “错误:找不到或无法加载主类someClass ” 的解决方案
- Latex表格太宽处理方法 (How to shorten Latex table length)
- Mac 下VIM配置
- 初识WCF1
- 安装系统+数据库+Sharepoint全套教程 (摘抄自https://www.cnblogs.com/jianyus/p/5482075.html)
- Java并发基础(上)——Thread
- December 30th 2016 Week 53rd Friday