1. class TimerShow extends egret.DisplayObjectContainer{
  2.  
  3. private now = new Date(); //当前日期
  4. private nowDayOfWeek = this.now.getDay(); //今天本周的第几天
  5. private nowDay = this.now.getDate(); //当前日
  6. private nowMonth = this.now.getMonth(); //当前月
  7. private nowYear = this.now.getFullYear(); //当前年
  8. // private lastMonthDate = new Date(); //上月日期
  9. // private lastYear = this.lastMonthDate.getFullYear();
  10. // private lastMonth = this.lastMonthDate.getMonth();
  11.  
  12. public constructor() {
  13. super();
  14. // this.addEventListener(egret.Event.ADDED_TO_STAGE,this.addToStage,this);
  15. }
  16. private addTiem(){
  17. this.nowYear += (this.nowYear < 2000) ? 1900 : 0;
  18. // this.lastMonthDate.setDate(1);
  19. // this.lastMonthDate.setMonth(this.lastMonthDate.getMonth()-1);
  20. }
  21. //格式化日期:yyyy-MM-dd
  22. public formatDate(date) {
  23. let myyear = date.getFullYear();
  24. let mymonth = date.getMonth()+1;
  25. let myweekday = date.getDate();
  26.  
  27. if(mymonth < 10){
  28. mymonth = "0" + mymonth;
  29. }
  30. if(myweekday < 10){
  31. myweekday = "0" + myweekday;
  32. }
  33. return (myyear+"-"+mymonth + "-" + myweekday);
  34. }
  35.  
  36. public formatReportDate(dates,specific){
  37. dates = new Date(dates);
  38. console.log(dates);
  39. let myyear = dates.getFullYear();
  40. let mymonth = dates.getMonth()+1;
  41. let myweekday = dates.getDate();
  42. let myday = dates.getDay();
  43. let hh = dates.getHours(); //时
  44. let mm = dates.getMinutes(); //分
  45. let ss = dates.getSeconds(); //秒
  46.  
  47. if(mymonth < 10){
  48. mymonth = "0" + mymonth;
  49. }
  50. if(myweekday < 10){
  51. myweekday = "0" + myweekday;
  52. }
  53. if(specific == 1){
  54. return (mymonth + "-" + myweekday + " "+GlobalVariable.getLangDay(myday) +" "+hh+":"+mm+":"+ss);
  55. }
  56. return (mymonth + "-" + myweekday + " "+GlobalVariable.getLangDay(myday) );
  57. }
  58.  
  59. public getCurrentDate(){
  60. let mymonth = this.now.getMonth()+1;
  61. let myweekday = this.now.getDate();
  62. if(mymonth < 10){
  63. mymonth = <any>"0" + mymonth;
  64. }
  65. if(myweekday < 10){
  66. myweekday = <any>"0" + myweekday;
  67. }
  68. let time = this.now.getFullYear()+"-"+mymonth+"-"+myweekday;
  69. return time;
  70. }
  71.  
  72. //获得某月的天数
  73. public getMonthDays(myMonth){
  74. this.addTiem();
  75. let monthStartDate:any = new Date(this.nowYear, myMonth, 1);
  76. let monthEndDate:any = new Date(this.nowYear, myMonth + 1, 1);
  77. let days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
  78. return days;
  79. }
  80. //获取昨天的日期
  81. public getYesterDay(thisTime){
  82. var time = new Date(thisTime); // 1 Feb -> 30 Jan
  83. time.setDate(time.getDate() - 1);
  84. let yesterDay = time.getFullYear()+"-" + (time.getMonth()+1) + "-" + time.getDate();
  85. return yesterDay;
  86. }
  87. //获取明天的日期
  88. public getTomorrow(thisTime){
  89. var time = new Date(thisTime); // 1 Feb -> 30 Jan
  90. time.setDate(time.getDate() +1);
  91. let mymonth = time.getMonth()+1;
  92. let myweekday = time.getDate();
  93. if(mymonth < 10){
  94. mymonth = <any>"0" + mymonth;
  95. }
  96. if(myweekday < 10){
  97. myweekday = <any>"0" + myweekday;
  98. }
  99. let Tomorrow = time.getFullYear()+"-" + mymonth + "-" + myweekday;
  100. return Tomorrow;
  101. }
  102.  
  103. //获得本季度的开始月份
  104. public getQuarterStartMonth(){
  105. let quarterStartMonth = 0;
  106. if(this.nowMonth<3){
  107. quarterStartMonth = 0;
  108. }
  109. if(2<this.nowMonth && this.nowMonth<6){
  110. quarterStartMonth = 3;
  111. }
  112. if(5<this.nowMonth && this.nowMonth<9){
  113. quarterStartMonth = 6;
  114. }
  115. if(this.nowMonth>8){
  116. quarterStartMonth = 9;
  117. }
  118. return quarterStartMonth;
  119. }
  120.  
  121. //获取七天前的日期
  122. public getSevenDaysDate(index){
  123. //index= -7;index= 7 前后
  124. let date = new Date(); //当前日期
  125. let newDate = new Date();
  126. newDate.setDate(date.getDate() + index);//官方文档上虽然说setDate参数是1-31,其实是可以设置负数的
  127. let mymonth = newDate.getMonth()+1;
  128. let myweekday = newDate.getDate();
  129. if(mymonth < 10){
  130. mymonth = <any>"0" + mymonth;
  131. }
  132. if(myweekday < 10){
  133. myweekday = <any>"0" + myweekday;
  134. }
  135. let time = newDate.getFullYear()+"-"+mymonth+"-"+myweekday;
  136. return time;
  137. }
  138.  
  139. //获得本周的开始日期
  140. public getWeekStartDate() {
  141. this.addTiem();
  142. let weekStartDate = new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek);
  143. return this.formatDate(weekStartDate);
  144. }
  145.  
  146. //获得本周的结束日期
  147. public getWeekEndDate() {
  148. this.addTiem();
  149. let weekEndDate = new Date(this.nowYear, this.nowMonth, this.nowDay + (6 - this.nowDayOfWeek));
  150. return this.formatDate(weekEndDate);
  151. }
  152. //获得上周的开始日期
  153. public getLastWeekStartDate() {
  154. let weekStartDate = new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek - 7);
  155. return this.formatDate(weekStartDate);
  156. }
  157. //获得上周的结束日期
  158. public getLastWeekEndDate() {
  159. let weekEndDate = new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek - 1);
  160. return this.formatDate(weekEndDate);
  161. }
  162.  
  163. //获得本月的开始日期
  164. public getMonthStartDate(){
  165. this.addTiem();
  166. let monthStartDate = new Date(this.nowYear, this.nowMonth, 1);
  167. return this.formatDate(monthStartDate);
  168. }
  169.  
  170. //获得本月的结束日期
  171. public getMonthEndDate(){
  172. this.addTiem();
  173. let monthEndDate = new Date(this.nowYear, this.nowMonth, this.getMonthDays(this.nowMonth));
  174. return this.formatDate(monthEndDate);
  175. }
  176.  
  177. //获得上月开始时间
  178. public getLastMonthStartDate(){
  179. let lastMonthDate = new Date(); //上月日期
  180. lastMonthDate.setDate(1);
  181. lastMonthDate.setMonth(lastMonthDate.getMonth() - 1);
  182. let lastYear = lastMonthDate.getFullYear();
  183. let lastMonth = lastMonthDate.getMonth();
  184.  
  185. let lastMonthStartDate = new Date(this.nowYear, lastMonth, 1);
  186. return this.formatDate(lastMonthStartDate);
  187. }
  188.  
  189. //获得上月结束时间
  190. public getLastMonthEndDate(){
  191. this.addTiem();
  192. let lastMonthDate = new Date(); //上月日期
  193. lastMonthDate.setDate(1);
  194. lastMonthDate.setMonth(lastMonthDate.getMonth() - 1);
  195. let lastYear = lastMonthDate.getFullYear();
  196. let lastMonth = lastMonthDate.getMonth();
  197.  
  198. let lastMonthEndDate = new Date(this.nowYear, lastMonth, this.getMonthDays(lastMonth));
  199. return this.formatDate(lastMonthEndDate);
  200. }
  201.  
  202. //获得本季度的开始日期
  203. public getQuarterStartDate(){
  204. this.addTiem();
  205. let quarterStartDate = new Date(this.nowYear, this.getQuarterStartMonth(), 1);
  206. return this.formatDate(quarterStartDate);
  207. }
  208.  
  209. //或的本季度的结束日期
  210. public getQuarterEndDate(){
  211. this.addTiem();
  212. let quarterEndMonth = this.getQuarterStartMonth() + 2;
  213. let quarterStartDate = new Date(this.nowYear, quarterEndMonth, this.getMonthDays(quarterEndMonth));
  214. return this.formatDate(quarterStartDate);
  215. }
  216. }

  

egret获取本周,上周,今天,昨天,明天,现在时间,今年,本月的更多相关文章

  1. java获取本周 上周的所有日期

    1 根据当前日期获得所在周的日期区间(周一和周日日期) public String getTimeInterval(Date date) { Calendar cal = Calendar.getIn ...

  2. Asp.net C# 获取本周上周本月上月本年上年第一天最后一天时间大全

    DateTime dt = DateTime.Now; int weeknow = Convert.ToInt32(DateTime.Now.DayOfWeek); ) * weeknow + ; D ...

  3. PHP获取本周的每一天的时间

    1.PHP获取未来一周的时间 public function getWeek() { for($i=0;$i<7;$i++) { $arr[$i]=date('Y-m-d',strtotime( ...

  4. 用php获取本周,上周,本月,上月,本季度日期的代码

    echo date("Ymd",strtotime("now")), "\n"; echo date("Ymd",str ...

  5. js获取本周、上周的开始结束时间

    这两天在做一个报表体统,其中涉及到了一个根据本周,上周,本月,上月的时间来进行查询的问题,在这个我就教一下大家怎么实现,大家如果有更好的实现方法的,我也希望大家能说出来,我们交流交流. 首先呢,我写了 ...

  6. [moka同学笔记]php 获取时间(今天,昨天,三天内,本周,上周,本月,三年内,半年内,一年内,三年内)

    <?php /** * php 获取时间(今天,昨天,三天内,本周,上周,本月,三年内,半年内,一年内,三年内) * * author:ihelloworld2010@gmail.com * d ...

  7. sql server2008 如何获取上月、上周、昨天、今天、本周、本月的查询周期(通过存储过程)

    我这边有一个需求要统计订单数据,需要统计订单的上传日期,统计的模块大概是 那么上月.上周.昨天.今天.本周.本月应该是怎样呢? 1.数据分析 因为今天是动态数据,我要查月份(上月.本月),应该是一个日 ...

  8. java获取当天,前天,明天,本周,本月,本年的开始日期时间和结束日期时间

    package demoone; import java.sql.Timestamp; import java.text.ParseException; import java.text.Simple ...

  9. php日期处理 -- 获取本周和上周的开始日期和结束日期(备忘)

    Learn From: http://www.phpernote.com/php-function/1019.html 直接贴代码: <?php header('Content-type: te ...

随机推荐

  1. 最短路径问题---Dijkstra算法详解

    侵删https://blog.csdn.net/qq_35644234/article/details/60870719 前言 Nobody can go back and start a new b ...

  2. net core 使用 rabbitmq

    windows环境安装: https://www.cnblogs.com/ericli-ericli/p/5902270.html .NET Core 使用RabbitMQ https://www.c ...

  3. 拒绝频繁IP访问--转载

    //首先我们要实现 IHttpModule接口 using System; using System.Collections.Generic; using System.Text; using Sys ...

  4. 关于K8S证书生成方面的脚本草稿

    周日在家里计划的. 俺不加班,但在家学习的时间一样没少! 还没弄完,只粗粗弄了etcd证书. #! /usr/bin/env bash set -e set -u set -x THIS_HOST=$ ...

  5. exception: java.net.ConnectException: Connection refused; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused

    1.虽然,不是大错,还说要贴一下,由于我运行run-example streaming.NetworkWordCount localhost 9999的测试案例,出现的错误,第一感觉就是Spark没有 ...

  6. std::string 是什么

    #include "stdafx.h" #include <iostream> #include <string> using std::cout; usi ...

  7. [转] mongoose学习笔记(超详细)

    名词解释 Schema: 一种以文件形式存储的数据库模型骨架,不具备数据库的操作能力 Model: 由Schema编译而成的假想(fancy)构造器,具有抽象属性和行为.Model的每一个实例(ins ...

  8. 流程图 Graphviz - Graph Visualization Software

    0.目录 1.参考 https://www.processon.com/  应该值得一试 知乎 用什么软件画流程图? 9款国内外垂直领域的在线作图工具[可代替visio] 程序员必知的七个图形工具 说 ...

  9. Ubuntu14.04创建无线WiFi,android可以连接上网

    前提条件: ubuntu14.04 unity,已经通过有线连接到internet 一般环境下创建的wifi热点android设备是无法识别的,网上说通过ap-hotspot方式创建出来的热点手机可以 ...

  10. RequireJS跨域加载html模版后被转成JS问题分析及解决

    问题描述 RequireJS跨域加载HTML模版失败,例如: 在a.com域名下请求CDN域名下的模版,text.js插件会把html文件转成html.js文件去加载,由于并没有生成html.js文件 ...