博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

判断当前日期的类型

Posted on 2012-11-19 09:26  人生梦想起飞  阅读(202)  评论(0编辑  收藏  举报

var DsrUtil = function(){
 //获取当前时间
 function getTime(type){
  var now = new Date();
  var year = now.getFullYear().toString();
  var month = (now.getMonth() + 1).toString();
     var day = now.getDate().toString();
  var hour = now.getHours().toString();
  var minute = now.getMinutes().toString();
  var second = now.getSeconds().toString();
  if (month.length == 1) {
         month = "0" + month;
     }
     if (day.length == 1) {
         day = "0" + day;
     }
  if (hour.length == 1) {
         hour = "0" + hour;
     }
     if (minute.length == 1) {
         minute = "0" + minute;
     }
     if (second.length == 1) {
         second = "0" + second;
     }
     if(type == "1"){
      return year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
     }else if(type == "2"){
      return year+"-"+month+"-"+day+" "+hour+":"+minute;
     }else if(type == "3"){
      return year+"-"+month+"-"+day;
     }else{
      return year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
     }
 }