编程语言
首页 > 编程语言> > JavaScript(jQuery)实现打印英文格式日期

JavaScript(jQuery)实现打印英文格式日期

作者:互联网

工作中遇到的功能点,觉得以后可以复用,就打算备一下咯

格式要求(例):On Friday, July 14, 2017

我的思路是用js就可以实现了,具体代码如下:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>index</title>
  </head>
  <body>
    <h1>Hello, world!</h1>
    <p class="current-time"></p>

    <script src="https://code.jquery.com/jquery-2.2.4.js"></script>

    <script type="text/javascript">
    $(function() {
      //全局对象
      //当前时间
      var curTime=new Date()

      //枚举周天
      var weekday=new Array(7);
      weekday[0]="Sunday";
      weekday[1]="Monday";
      weekday[2]="Tuesday";
      weekday[3]="Wednesday";
      weekday[4]="Thursday";
      weekday[5]="Friday";
      weekday[6]="Saturday";

      //枚举月份
      var month=new Array(12);
      month[0]="January";
      month[1]="February";
      month[2]="March";
      month[3]="April";
      month[4]="May";
      month[5]="June";
      month[6]="July";
      month[7]="August";
      month[8]="September";
      month[9]="October";
      month[10]="November";
      month[11]="December";

      //当前日期信息
      var strCurTime = "On " + weekday[curTime.getDay()] +", "+month[curTime.getMonth()] + " " + curTime.getDate() + ", " + curTime.getFullYear();
      $(".current-time").html(strCurTime);
    });
    </script>
  </body>
</html>

 

标签:jQuery,Friday,JavaScript,month,weekday,curTime,new,var,格式
来源: https://www.cnblogs.com/hsiaochinchin/p/14013256.html