js时间格式化函数,支持Unix时间戳
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>js时间格式化函数,支持Unix时间戳</title>
</head>
<body>
<script>
/**
Date 对象方法大全
http://www.w3school.com.cn/jsref/jsref_obj_date.asp
可传入Unix时间戳。单位秒,默认返回当前时间
ts==timestamp
author::jom_ch@2014/7/2
**/
function getTime(/** timestamp=0 **/) {
var ts = arguments[0] || 0;
var t,y,m,d,h,i,s;
t = ts ? new Date(ts*1000) : new Date();
y = t.getFullYear();
m = t.getMonth()+1;
d = t.getDate();
h = t.getHours();
i = t.getMinutes();
s = t.getSeconds();
// 可依据须要在这里定义时间格式
return y+'-'+(m<10?'0'+m:m)+'-'+(d<10? '0'+d:d)+' '+(h<10?'0'+h:h)+':'+(i<10?'0'+i:i)+':'+(s<10?'0'+s:s);
} alert(getTime(1404276301)); </script> </body>
</html>
js时间格式化函数,支持Unix时间戳的更多相关文章
- JS 时间格式化函数
//时间格式化函数 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, ...
- js时间格式化函数(兼容IOS)
* 时间格式化 * @param {Object} dateObj 时间对象 * @param {String} fmt 格式化字符串 */ dateFormat(dateObj, fmt) { le ...
- JS时间格式化函数
Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, //month & ...
- 时间戳显示为多少分钟前,多少天前的JS处理,JS时间格式化,时间戳的转换
var dateDiff = function (timestamp) { // 补全为13位 var arrTimestamp = (timestamp + '').split(''); for ( ...
- js 日期格式化函数(可自定义)
js 日期格式化函数 DateFormat var DateFormat = function (datetime, formatStr) { var dat = datetime; var str ...
- mysql时间格式化函数日期格式h和H区别
本文为博主原创,未经允许不得转载: 今天碰到一个问题,发现项目中有一个统计图的数据和时间格式没有对应准确,统计图要描述的是操作次数和操作时间的关系, 但很奇怪的是操作次数对应的时间却是凌晨,实际应用中 ...
- js 时间格式化 (兼容safari)
js 时间格式化,兼容IE8和safari浏览器. function formatDate(date, fmt, near, type) { var dateStr = date; if (!date ...
- JavaScript日期时间格式化函数
这篇文章主要介绍了JavaScript日期时间格式化函数分享,需要的朋友可以参考下 这个函数经常用到,分享给大家. 函数代码: //格式化参数说明: //y:年,M:月,d:日,h:时,m分,s:秒, ...
- SQL 时间格式化函数发布
SQL 时间格式化函数,有时候因某种需要需要格式化成需要的时间格式,需要的朋友可以收藏下,以备后用. SQL Server里面可能经常会用到的日期格式转换方法: sql server使用convert ...
随机推荐
- ASP.NET-Active Direcotry编程示例
查找指定的AD帐号 using (DirectoryEntry de = new DirectoryEntry("LDAP://RootDSE")) { string DCName ...
- maven打包可运行的jar包(包含依赖工程)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- POJ 1107
水题一道,注意取模时不能为0 #include <iostream> #include <algorithm> #include <cstring> #includ ...
- [CSS3] The different of Background-size between 'cover' and 'contain'
'cover': The smaller axies of image (x axies) should match smaller axies (x axies) of container. So ...
- 关于Blog使用
1.网易博客http://inowtofuture.blog.163.com/blog/#m=0 使用时间:2011年8月-2012年2月 记录内容:主要记录本科參加ACM期间在POJ(北京大学OJ) ...
- Android圆形图片--自己定义控件
Android圆形图片控件效果图例如以下: 代码例如以下: RoundImageView.java package com.dxd.roundimageview; import android.con ...
- bzoj3275: Number(最小割)
3275: Number 题目:传送门 题解: 双倍经验@bzoj3158 代码: #include<cstdio> #include<cstring> #include< ...
- GIT GUI简易教程
GIT GUI简易教程 前言 之前一直想一篇这样的东西,因为最初接触时,我也认真看了廖雪峰的教程,但是似乎我觉得讲得有点多,而且还是会给我带来很多多余且重复的操作负担,所以我希望能压缩一下它在我工作中 ...
- CentOS7安装第三方yum源EPEL
转自:https://blog.csdn.net/u012208775/article/details/78784616 一.简介 EPEL是企业版 Linux 附加软件包的简称,EPEL是一个由Fe ...
- Matplotlib画图可选颜色
经常会有画图找不到合适颜色的尴尬情景, 在网上找到一张matplotlib可以用的颜色图: