以前寫的非常low的js格式化日期function

Phoenix Phoenix 2018.2.8 00:00 浏览(314) 评论 (0)
function setDateFormatInput(obj, languageVersion) {
   if (obj == null) {
      return "";
   }
   if (obj.length != 0) {
      var content = "";
      var result = "";
      if (typeof obj == "object") {
         if (obj instanceof Date) {
            var vYear = obj.getFullYear()
            var vMon = obj.getMonth() + 1
            var vDay = obj.getDate();
            switch (languageVersion) {
            case "0":// 中文
               s = (vDay < 10 ? "0" + vDay : vDay) + 
                  "/" + (vMon < 10 ? "0" + vMon : vMon) + "/" + vYear;
               break;
            case "1":// 英文
               s = (vDay < 10 ? "0" + vDay : vDay) + "/" + 
               (vMon < 10 ? "0" + vMon : vMon) + "/" + vYear;
               break;
            }// end switch
            return s
         } else if (obj.attr("type") == "text") {
            obj.each(function() {
               content = $(this).val();
               if (content != "") {
                  switch (languageVersion) {
                  case "0":// 中文
                     result = content.substr(8, 2) + "/" + content.substr(5, 2) +
                        "/" + content.substr(0, 4);
                     break;
                  case "1":// 英文
                     result = content.substr(8, 2) + "/" + content.substr(5, 2) + 
                        "/" + content.substr(0, 4);
                     break;
                  }// end switch
                  $(this).val(result);
               }
            })// end each
         }
      } else {
         content = obj;
         if (content != "") {
            switch (languageVersion) {
            case "0":// 中文
               result = content.substr(8, 2) + "/" + content.substr(5, 2) + "/" + 
                  content.substr(0, 4);
               break;
            case "1":// 英文
               result = content.substr(8, 2) + "/" + content.substr(5, 2) + "/" + 
                  content.substr(0, 4);
               break;
            }// end switch
            return result;
         } else {
            return "";
         }
      }
   }// end if obj.length !=0
}

 

本文链接 https://www.mangoxo.com/blog/dp5Xblxg 版权所有,转载请保留地址链接,感谢!

Phoenix 关注
來一遭,做一事。 等一人,愛一次。
  • 959 动态
  • 1,989 相册
  • 144 粉丝
  • 3,052 获赞