<html>
<body> <script type="text/javascript"> //将long 型 转换为 日期格式 年-月-日 h:m:s
function getDateStringTools(date, pattern){
var dt = new Date(Number(date));
var year = dt.getFullYear();
var month = dt.getMonth()+1;
var day =dt.getDate();
var h = dt.getHours();
var m = dt.getMinutes();
var s = dt.getSeconds();
var strDate;
if(month<10){month ="0" + month;}
if(day<10){day = "0" + day;}
if(h<10){h = "0" + h;}
if(m<10){m = "0" + m;}
if(s<10){s = "0" + s;}
//2013-10-08 14:32 yyyy-MM-dd hh:mm
var date_0 = /^y{4}-M{2}-d{2}\s*$/;
//2013-10-08 14:32 yyyy-MM-dd hh:mm
var date_1 = /^y{4}-M{2}-d{2}\s*h{2}:m{2}$/;
//2013-10-08 14:32:09 yyyy-MM-dd hh:mm:ss
var date_2 = /^y{4}-M{2}-d{2}\s*h{2}:m{2}:s{2}$/;
//2013年10月08 14:32 yyyy年MM月dd hh:mm
var date_3 = /^y{4}年M{2}月d{2}\s*$/;
//2013-10-08 14:32 yyyy年MM月dd hh:mm
var date_4 = /^y{4}年M{2}月d{2}\s*h{2}:m{2}$/;
//2013-10-08 14:32:09 yyyy年MM月dd hh:mm:ss
var date_5 = /^y{4}年M{2}月d{2}\s*h{2}:m{2}:s{2}$/; if (date_0.test(pattern)) {
strDate = year+"-" + month+"-" + day;
} else if (date_1.test(pattern)) {
strDate = year+"-" + month+"-" + day+"&nbsp;" + h+":" + m;
} else if (date_2.test(pattern)) {
strDate = year+"-" + month+"-" + day+"&nbsp;" + h+":" + m+":" + s;
} else if (date_3.test(pattern)) {
strDate = year+"年" + month+"月" + day;
} else if (date_4.test(pattern)) {
strDate = year+"年" + month+"月" + day+"&nbsp;" + h+":" + m;
} else if (date_5.test(pattern)) {
strDate = year+"年" + month+"月" + day+"&nbsp;" + h+":" + m+":" + s;
} return strDate;
} document.write(getDateStringTools(1381213929988,'yyyy年MM月dd hh:mm:ss'));
alert(getDateStringTools(1381213929988,'yyyy年MM月dd hh:mm:ss'));
</script> </body>
</html>

Js正则匹配处理时间的更多相关文章

  1. js正则匹配的一个日常应用

    应用实例 1 /** 将段落中的 \n 转换为 <p></p>, 规范存储 */ 2 function formatParagraphForStore(val) { 3 var ...

  2. JS正则密码复杂度校验之:JS正则匹配半角英文符号

    概述 在JS密码校验中常常会遇到密码强度的校验需求,借用一位朋友提问的图,他在工作中遇到的一个比较经典的密码强度校验要求: 这个需求有两个难点,一,是如何使用正则匹配所有半角英文标点符号,二,是如何验 ...

  3. js正则匹配两位小数

    今天写一个用js正则校验最多保留两位小数的格式. a = /^\d+|\d+\.\d{1,2}$/; 测试 a.test(1.222); 结果:true 一下蒙了,怎么可能,最后找了好久,原来需要把^ ...

  4. js 正则匹配 域名【host】

    如果直接在js中是可以直接取到hostname的,以下方式是通过正则匹配: var url = "http://www.cnblogs.com/cench" var reg = / ...

  5. js 正则匹配(去掉html标签)

    正则匹配去掉所有html标签 var a = "<span>999</span>" a = a.replace(/<[^>]+>/g,' ...

  6. js正则匹配字符串

    这里我第一时间想到的就是用 js 的search 和 match ,其中最常见的是match: 1. str.search(regexp):search()方法不支持全局搜索,因为会忽略正则表达式参数 ...

  7. js正则匹配table,img及去除各种标签问题

    //获取公示栏内容 s = "$row.detail$"; mainContent =s; //如果有多个table使用下面注释的正则只会匹配成一个table //var tabR ...

  8. js正则匹配以某字符串开始字符串

    let decode_sql ="select * from table where create_user='user' order by id desc";   decode_ ...

  9. js 正则匹配 小结

    JS的正则表达式 rge.test(str) 检验目标对象中是否包含匹配模式,并相应的返回true或false   rge.source str.search(rge) 将返回一个整数值,指明这个匹配 ...

随机推荐

  1. POJ - 3541 - Given a string…

    Given a string… Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 1819   Accepted: 390 C ...

  2. jQuery WEI----DIV+CSS样式li自动适应高度,自动换行,横向排列

    设置相关样式即可,按照需求自己修改样式,Demo代码如下: <li style="display:inline;;line-height:24px;height:auto;word-b ...

  3. [poj2396]Buget[上下界可行流]

    题意:有一个n*m的方阵,里面的数字未知,但是我们知道如下约束条件:每一行的数字的和每一列的数字的和某些格子有特殊的大小约束,用大于号,小于号和等于号表示问:是否存在用正数填充这个方阵的方案,满足所有 ...

  4. 网络流入门 Drainage Ditches

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) ...

  5. OpenCV使用GPU

    在使用OpenCV2.4.x的时候,以为不用重新编译可以直接使用GPU模块,不过在我使用的时候,发现使用getCudaEnabledDeviceCount()的时候,总是获得是0,于是重新编译Open ...

  6. HTML5:防止页面在移动设备上缩放

    在制作网页时,如果对移动设备有做兼容设计的话,通常是不希望页面在移动设备能够被缩放.这样可以防止原先设计好的样式被破坏.要做到这一点,只需要在网页的head部分加入如下语句即可: <!-- 屏蔽 ...

  7. 每一个程序猿必知之SEO

    似乎由于受这篇文章的影响 http://katemats.com/what-every-programmer-should-know-about-seo/ 于是我也觉得我应该写一个每一个程序猿必知之S ...

  8. poj--3061--Subsequence(贪心)

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10882   Accepted: 4498 Desc ...

  9. leetcode链表相关

    目录 2/445两数相加 综合题(328奇偶链表, 206反转链表, 21合并两个有序链表 ) 92反转链表 II 链表排序(148排序链表, 876链表的中间结点) 142环形链表 II 160相交 ...

  10. 七牛php上传下载类,集成官方文档的方法

    <?phpuse Qiniu\Auth;use Qiniu\Storage\UploadManager;class qiniu{ public $_accesskey = null; publi ...