zoukankan      html  css  js  c++  java
  • 时间格式

    frontOneHour(fmt) {
          var currentTime = new Date(new Date().getTime());
          // console.log(currentTime); // Wed Jun 20 2018 16:12:12 GMT+0800 (中国标准时间)
          var o = {
            "M+": currentTime.getMonth() + 1, // 月份
            "d+": currentTime.getDate(), //
            "h+": currentTime.getHours(), // 小时
            "m+": currentTime.getMinutes(), //
            "s+": currentTime.getSeconds(), //
            "q+": Math.floor((currentTime.getMonth() + 3) / 3), // 季度
            S: currentTime.getMilliseconds() // 毫秒
          };
          if (/(y+)/.test(fmt))
            fmt = fmt.replace(
              RegExp.$1,
              (currentTime.getFullYear() + "").substr(4 - RegExp.$1.length)
            );
          for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt))
              fmt = fmt.replace(
                RegExp.$1,
                RegExp.$1.length === 1
                  ? o[k]
                  : ("00" + o[k]).substr(("" + o[k]).length)
              );
          }
          return fmt;
        },

    调用方法:

    frontOneHour("yyyy年MM月dd日 hh:mm:ss");
    frontOneHour("yyyy/MM/dd hh:mm:ss");
    frontOneHour("yyyy-MM-dd- hh:mm:ss");
  • 相关阅读:
    C#异步编程:多线程基础Thread类
    WPF:TextBox控件禁用中文输入
    C#:泛型的协变和逆变
    C#:泛型接口
    C#:泛型委托
    C#:泛型类
    Jetbrains Rider:缺少.NET Framework 4.5.2
    C#:泛型方法
    C#:泛型
    C#:接口
  • 原文地址:https://www.cnblogs.com/zhanghailing/p/13667405.html
Copyright © 2011-2022 走看看