• javascript时间格式化


    对于从后台数据库读取出来的时间格式有时并不是我们想要的格式。

    要想使用java的SimpleDateFormat是实现不了时间格式化的,不过在在http://www.javascriptsource.com网站上有有个时间格式化的类库

    只要在页面引入这个类库<script type="text/javascript" language="JavaScript" src="JsSimpleDateFormat.js"></script>

    就可轻松实现时间的格式化

    <html>
     <head>
      <title> New Document </title>
          <script type="text/javascript" language="JavaScript" src="JsSimpleDateFormat.js"></script>
        <script type="text/javascript">
        
        function getFormatDate(){
            var oDf = new JsSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            //var oDf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");    //实现不了时间格式化

      //如何对时间格式化直接new Date();
            alert(oDf.format(new Date()));

      //假如后台传来的是字符串类型就对new Date(str),str代表时间格式的字符串

      //alert(oDf.format(new Date(str));
        }
        </script>
      <meta name="Generator" content="EditPlus">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">

     </head>
    <input type="button" value="获取时间" onclick="getFormatDate()"/>
     <body>
     
     </body>
    </html>
    类库的下载地址http://www.javascriptsource.com/repository/javascripts/2009/03/880961/JS_Simple_Date_Format.zip

  • 相关阅读:
    2019 SDN上机第7次作业
    2019 SDN上机第六次作业
    2019 SDN上机第5次作业
    SDN课程阅读作业(2)
    2019 SDN上机第4次作业
    2019 SDN阅读作业
    2019 SDN上机第3次作业
    第09组 团队Git现场编程实战
    预习非数值数据的编码方式
    预习原码补码
  • 原文地址:https://www.cnblogs.com/charleszhang1988/p/javascript.html
Copyright © 2020-2023  润新知