<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. PatentTips - Invalidating TLB entries in a virtual machine system

    BACKGROUND This invention relates to virtual machines. In particular, the invention relates to trans ...

  2. angular5 httpclient的示例实战

    摘要: 从angular 4.3.0 以后的版本开始使用httpclient,替换了之前的http,引用的包路径已经变为了angular/common/http了 一个基础的 httpclient 样 ...

  3. ZZUOJ-1195-OS Job Scheduling(郑州大学第七届ACM大学生程序设计竞赛E题)

    1195: OS Job Scheduling Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 106  Solved: 35 [id=1195&quo ...

  4. erlang Unicode 处理

    最近在使用erlang做游戏服务器,而字符串在服务器编程中的地位是十分重要的,于是便想仔细研究下字符编码,以及erlang下的字符串处理.先从Unicode开始吧.... [Unicode] Unic ...

  5. machine learning in coding(python):使用贪心搜索【进行特征选择】

    print "Performing greedy feature selection..." score_hist = [] N = 10 good_features = set( ...

  6. Universal-Image-Loader(android图片缓存)

    转载请注明http://write.blog.csdn.net/postedit?ref=toolbar 点击下载所需jar文件 具体资料整理请加群284568173自行下载pdf 项目介绍: And ...

  7. 通过指针访问C++对象的私有成员

    C++对象的私有成员是禁止类外的访问的.但是我们仍然可以通过指针访问C++对象的私有成员. #include <iostream> using namespace std; class A ...

  8. How to do IF NOT EXISTS in SQLite

    http://stackoverflow.com/questions/531035/how-to-do-if-not-exists-in-sqlite How about this? INSERT O ...

  9. Mongo 中间件 pre find 修改query

    需求:在所有find查询的时候,默认添加查询参数 name:bennman //创建一个query中间件 myMid.js module.exports = function(schema){ //这 ...

  10. 杂项-Company:ShineYoo

    ylbtech-杂项-Company:ShineYoo 1. 网站返回顶部 1. 2. 3. 4. 2. 网站测试返回顶部 1. 2. 3.家服宝返回顶部 0.首页 http://www.jiafb. ...