zoukankan      html  css  js  c++  java
  • Fri Oct 31 18:00:00 UTC+0800 2008转换为yyyy-mm-dd

    这个其实网上有很多例子,都是直接用js在前端做了时间处理,我的处理也一样,想要变成2008-3-31,就用下面的js直接可以处理
        function Todate(num) { //Fri Oct 31 18:00:00 UTC+0800 2008
            num = num + "";
            var date = "";
            var month = new Array();
            month["Jan"] = 1; month["Feb"] = 2; month["Mar"] = 3; month["Apr"] = 4; month["May"] = 5; month["Jun"] = 6;
            month["Jul"] = 7; month["Aug"] = 8; month["Sep"] = 9; month["Oct"] = 10; month["Nov"] = 11; month["Dec"] = 12;
            var week = new Array();
            week["Mon"] = "一"; week["Tue"] = "二"; week["Wed"] = "三"; week["Thu"] = "四"; week["Fri"] = "五"; week["Sat"] = "六"; week["Sun"] = "日";
            str = num.split(" ");
            date = str[5] + "-";
            date = date + month[str[1]] + "-" + str[2];//获取到的年月日,要是想加上时分秒,就date = date + month[str[1]] + "-" + str[2]+ " " + str[3];
            return date;
        }
    
    
    

     我正好做项目,时间要转换成2008-03,我就直接加了个判断

    function spliceZero(param)
    		{
    		    if (param < 10) {
    		    param = "0" + param;
    		}
    		    return param;
    		} 


    /**
    * 下面给个完整的例子
    *
    **/


    function Todate(num) { //Fri Oct 31 18:00:00 UTC+0800 2008
                if(num!=""){
                    num = num + "";
                    var date = "";
                    var month = new Array();
                    month["Jan"] = 1; month["Feb"] = 2; month["Mar"] = 3; month["Apr"] = 4; month["May"] = 5; month["Jun"] = 6;
                    month["Jul"] = 7; month["Aug"] = 8; month["Sep"] = 9; month["Oct"] = 10; month["Nov"] = 11; month["Dec"] = 12;
                    str = num.split(" ");
                    date = str[5] + "-";
                    date = date + spliceZero(month[str[1]]);
                    return date;
                }else{
                     return "";
                }
                
            }
            
            function spliceZero(param)
            {
                if (param < 10) {
                param = "0" + param;
            }
                return param;
            }
     
  • 相关阅读:
    Python Day 5 数字、字符串、列表、可变与不可变
    Python day 4 流程控制
    Python Day 3 变量命名规范、格式化输出
    python 实践项目
    python 实践项目 强密码检测
    Python Day 2
    SSH:分页实现
    SSH:dataSource配置问题
    关于 struts2 Unable to load configuration.
    题目1522:包含min函数的栈
  • 原文地址:https://www.cnblogs.com/junrong624/p/7084873.html
Copyright © 2011-2022 走看看