//扩展Date的format方法
Date.prototype.format = function (format) {
var o = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
}
/**
*转换日期对象为日期字符串
* @param date 日期对象
* @param isFull 是否为完整的日期数据,
* 为true时, 格式如"2000-03-05 01:05:04"
* 为false时, 格式如 "2000-03-05"
* @return 符合要求的日期字符串
*/
function getSmpFormatDate(date, isFull) {
var pattern = "";
if (isFull == true || isFull == undefined) {
pattern = "yyyy-MM-dd hh:mm:ss";
} else {
pattern = "yyyy-MM-dd";
}
return getFormatDate(date, pattern);
}
/**
*转换当前日期对象为日期字符串
* @param date 日期对象
* @param isFull 是否为完整的日期数据,
* 为true时, 格式如"2000-03-05 01:05:04"
* 为false时, 格式如 "2000-03-05"
* @return 符合要求的日期字符串
*/
function getSmpFormatNowDate(isFull) {
return getSmpFormatDate(new Date(), isFull);
}
/**
*转换long值为日期字符串
* @param l long值
* @param isFull 是否为完整的日期数据,
* 为true时, 格式如"2000-03-05 01:05:04"
* 为false时, 格式如 "2000-03-05"
* @return 符合要求的日期字符串
*/
function getSmpFormatDateByLong(l, isFull) {
return getSmpFormatDate(new Date(l), isFull);
}
/**
*转换long值为日期字符串
* @param l long值
* @param pattern 格式字符串,例如:yyyy-MM-dd hh:mm:ss
* @return 符合要求的日期字符串
*/
function getFormatDateByLong(l, pattern) {
return getFormatDate(new Date(l), pattern);
}
/**
*转换日期对象为日期字符串
* @param l long值
* @param pattern 格式字符串,例如:yyyy-MM-dd hh:mm:ss
* @return 符合要求的日期字符串
*/
function getFormatDate(date, pattern) {
if (date == undefined) {
date = new Date();
}
if (pattern == undefined) {
pattern = "yyyy-MM-dd hh:mm:ss";
}
return date.format(pattern);
}

$(".releaseDate").each(function(i){
$(this).text(getSmpFormatDateByLong(Number($(this).text()),true));
})

用js 将long类型转换成日期格式的更多相关文章

  1. js时间戳怎么转成日期格式

    原文地址:http://www.sufeinet.com/thread-1500-1-1.html js时间戳怎么转成日期格式这个在主群里有朋友§☆釺哖蟲...o问js时间戳怎么转成日期格式 ,他的问 ...

  2. js angular 时间戳转换成日期格式 年月日 yyyy-MM-dd

    昨天写项目,要把时间戳转换成日期格式发给后端 我就去网上找 看到的一些都不是我想要的 索性自己就写了一个如图 下面是angular 模式 $scope.getMyDate = function(str ...

  3. js将时间戳转换成日期格式-陈远波

    var timestamp =1539598555000;//时间戳 //时间戳转换成time格式function timestampToTime(timestamp) { var date = ne ...

  4. js时间戳转成日期格式

    将时间戳转换成日期格式:// 简单的一句代码var date = new Date(时间戳); //获取一个时间对象 注意:如果是uinx时间戳记得乘于1000.比如php函数time()获得的时间戳 ...

  5. 将序列化成json格式的日期(毫秒数)转成日期格式

    <script> $(function () { loadInfo(); }) function loadInfo() { $.post("InfoList.ashx" ...

  6. CTime,Systemtime的比较还有转换成日期格式。

    vc为我们提供了两种日期型的变量. 一种是CTime.他的缺点就是年份只支持到2038年,以后的日期就不支持啦,如果你的项目有20-30年的寿命,你就选择使用SYSTEMTIME.这个时间函数来进行比 ...

  7. js中时间戳转换成时间格式

    js中时间戳转换成时间格式, // 时间戳转换成时间格式 var formatDate = function(date){ date = new Date(date); var y=date.getF ...

  8. JS中Unix时间戳转换日期格式

    <!doctype html> <html> <head> <title>Unix时间戳转换成日期格式</title> <script ...

  9. time_t转化成日期格式小工具

    time_t转化成日期格式小工具下载  http://files.cnblogs.com/files/lansan0701/TimeTool.zip

随机推荐

  1. 如何占用你用户的时间 and 如何提高客户的满意度 。 待续

    未来的商业竞争, 可能本质上是在争取客户的时间 嗯..有不定时, 未知的奖励,游戏行业就经常使用, 比如打怪掉装备, 不一定掉什么好东西, 让人充满了期待, 玛雅宝石, 有一定的概率... 觉得公司员 ...

  2. C# lesson2

    一.C#数据类型 1.值类型 包括数据相关(short.long.int .double.float).布尔(bool).枚举 2.引用类型 Object .对象.数组.字符串 二.存储方式 值类型 ...

  3. css display属性介绍

    none此元素不会被显示. block此元素将显示为块级元素,此元素前后会带有换行符. inline默认.此元素会被显示为内联元素,元素前后没有换行符. inline-block行内块元素.(CSS2 ...

  4. ExceptionDemo

    功能: 利用struts.xml 捕获异常  不满足这三个值就报异常 1.web.xml <?xml version="1.0" encoding="UTF-8&q ...

  5. oracle之nomount、mount、open三种状态

    1.先来看下外国网站上的资料怎么说 Nomount – The database instance has been started (processes and memory structures ...

  6. intellij idea 12 搭建maven web项目 freemarker + spring mvc

    配置spring mvc ,写这篇文章的时候spring已经出了4.0 这里还是用稳定的3.2.7.RELEASE,先把spring和freemarker配置好 1.spring mvc配置 在web ...

  7. CodeForces 703A Mishka and Game

    简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu ...

  8. 第九十八节,JavaScript语法、关键保留字及变量

    JavaScript语法.关键保留字及变量 学习要点: 1.语法构成 2.关键字保留字 3.变量 任何语言的核心都必然会描述这门语言最基本的工作原理.而JavaScript的语言核心就是ECMAScr ...

  9. LINQ里的“equals”和“==”的区别

    对于值类型,如果对象的值相等,则相等运算符 (==) 返回 true,否则返回 false.对于string 以外的引用类型,如果两个对象引用同一个对象,则 == 返回 true.对于 string ...

  10. 彻底卸载 postgreSQL .etc

    sudo apt-get  --purge autoremove postgresql*