zoukankan      html  css  js  c++  java
  • js时间戳转日期

        //时间戳转日期  2017-04-30 13:20
        //type=1--> 2017-04-30 13:20
        //type=2-->2018年08月
        //type=3-->2018-08-30
        function time_conversion(stamp,type){
            var date = new Date(stamp*1000),
                year = date.getFullYear(),
                month = date.getMonth() + 1 <10? '0' + (date.getMonth()+1) : date.getMonth()+1,
                dat = date.getDate() < 10 ? '0'+date.getDate() : date.getDate(),
                day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()],
                hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
                minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
                second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
            var currentTime = year + "-" + month + "-" + dat + " " + hour + ":" + minute;
            var currentTime2 = year + "年" + month + "月";
            var currentTime3 = year + "-" + month + "-" + dat;
            if(type == 1){
                return currentTime;
            }
    
            if(type == 2){
                return currentTime2;
            }
    
            if(type == 3){
                return currentTime3;
            }
        }
        调用方法:console.log(time_conversion('1535595014',4));
  • 相关阅读:
    kindle--瓦尔登湖
    8051
    c++
    Linux安装目录的选择
    Redis键值数据类型之散列类型
    Redis键值数据类型之字符串
    redis基本使用
    Ubuntu18.04 Redis安装
    Java String和int转换
    mysql获得自增主码的值
  • 原文地址:https://www.cnblogs.com/liubingyjui/p/10375115.html
Copyright © 2011-2022 走看看