class TimerShow extends  egret.DisplayObjectContainer{

    private now = new Date(); //当前日期
private nowDayOfWeek = this.now.getDay(); //今天本周的第几天
private nowDay = this.now.getDate(); //当前日
private nowMonth = this.now.getMonth(); //当前月
private nowYear = this.now.getFullYear(); //当前年
// private lastMonthDate = new Date(); //上月日期
// private lastYear = this.lastMonthDate.getFullYear();
// private lastMonth = this.lastMonthDate.getMonth(); public constructor() {
super();
// this.addEventListener(egret.Event.ADDED_TO_STAGE,this.addToStage,this);
}
private addTiem(){
this.nowYear += (this.nowYear < 2000) ? 1900 : 0;
// this.lastMonthDate.setDate(1);
// this.lastMonthDate.setMonth(this.lastMonthDate.getMonth()-1);
}
//格式化日期:yyyy-MM-dd
public formatDate(date) {
let myyear = date.getFullYear();
let mymonth = date.getMonth()+1;
let myweekday = date.getDate(); if(mymonth < 10){
mymonth = "0" + mymonth;
}
if(myweekday < 10){
myweekday = "0" + myweekday;
}
return (myyear+"-"+mymonth + "-" + myweekday);
} public formatReportDate(dates,specific){
dates = new Date(dates);
console.log(dates);
let myyear = dates.getFullYear();
let mymonth = dates.getMonth()+1;
let myweekday = dates.getDate();
let myday = dates.getDay();
let hh = dates.getHours(); //时
let mm = dates.getMinutes(); //分
let ss = dates.getSeconds(); //秒 if(mymonth < 10){
mymonth = "0" + mymonth;
}
if(myweekday < 10){
myweekday = "0" + myweekday;
}
if(specific == 1){
return (mymonth + "-" + myweekday + " "+GlobalVariable.getLangDay(myday) +" "+hh+":"+mm+":"+ss);
}
return (mymonth + "-" + myweekday + " "+GlobalVariable.getLangDay(myday) );
} public getCurrentDate(){
let mymonth = this.now.getMonth()+1;
let myweekday = this.now.getDate();
if(mymonth < 10){
mymonth = <any>"0" + mymonth;
}
if(myweekday < 10){
myweekday = <any>"0" + myweekday;
}
let time = this.now.getFullYear()+"-"+mymonth+"-"+myweekday;
return time;
} //获得某月的天数
public getMonthDays(myMonth){
this.addTiem();
let monthStartDate:any = new Date(this.nowYear, myMonth, 1);
let monthEndDate:any = new Date(this.nowYear, myMonth + 1, 1);
let days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
return days;
}
//获取昨天的日期
public getYesterDay(thisTime){
var time = new Date(thisTime); // 1 Feb -> 30 Jan
time.setDate(time.getDate() - 1);
let yesterDay = time.getFullYear()+"-" + (time.getMonth()+1) + "-" + time.getDate();
return yesterDay;
}
//获取明天的日期
public getTomorrow(thisTime){
var time = new Date(thisTime); // 1 Feb -> 30 Jan
time.setDate(time.getDate() +1);
let mymonth = time.getMonth()+1;
let myweekday = time.getDate();
if(mymonth < 10){
mymonth = <any>"0" + mymonth;
}
if(myweekday < 10){
myweekday = <any>"0" + myweekday;
}
let Tomorrow = time.getFullYear()+"-" + mymonth + "-" + myweekday;
return Tomorrow;
} //获得本季度的开始月份
public getQuarterStartMonth(){
let quarterStartMonth = 0;
if(this.nowMonth<3){
quarterStartMonth = 0;
}
if(2<this.nowMonth && this.nowMonth<6){
quarterStartMonth = 3;
}
if(5<this.nowMonth && this.nowMonth<9){
quarterStartMonth = 6;
}
if(this.nowMonth>8){
quarterStartMonth = 9;
}
return quarterStartMonth;
} //获取七天前的日期
public getSevenDaysDate(index){
//index= -7;index= 7 前后
let date = new Date(); //当前日期
let newDate = new Date();
newDate.setDate(date.getDate() + index);//官方文档上虽然说setDate参数是1-31,其实是可以设置负数的
let mymonth = newDate.getMonth()+1;
let myweekday = newDate.getDate();
if(mymonth < 10){
mymonth = <any>"0" + mymonth;
}
if(myweekday < 10){
myweekday = <any>"0" + myweekday;
}
let time = newDate.getFullYear()+"-"+mymonth+"-"+myweekday;
return time;
} //获得本周的开始日期
public getWeekStartDate() {
this.addTiem();
let weekStartDate = new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek);
return this.formatDate(weekStartDate);
} //获得本周的结束日期
public getWeekEndDate() {
this.addTiem();
let weekEndDate = new Date(this.nowYear, this.nowMonth, this.nowDay + (6 - this.nowDayOfWeek));
return this.formatDate(weekEndDate);
}
//获得上周的开始日期
public getLastWeekStartDate() {
let weekStartDate = new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek - 7);
return this.formatDate(weekStartDate);
}
//获得上周的结束日期
public getLastWeekEndDate() {
let weekEndDate = new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek - 1);
return this.formatDate(weekEndDate);
} //获得本月的开始日期
public getMonthStartDate(){
this.addTiem();
let monthStartDate = new Date(this.nowYear, this.nowMonth, 1);
return this.formatDate(monthStartDate);
} //获得本月的结束日期
public getMonthEndDate(){
this.addTiem();
let monthEndDate = new Date(this.nowYear, this.nowMonth, this.getMonthDays(this.nowMonth));
return this.formatDate(monthEndDate);
} //获得上月开始时间
public getLastMonthStartDate(){
let lastMonthDate = new Date(); //上月日期
lastMonthDate.setDate(1);
lastMonthDate.setMonth(lastMonthDate.getMonth() - 1);
let lastYear = lastMonthDate.getFullYear();
let lastMonth = lastMonthDate.getMonth(); let lastMonthStartDate = new Date(this.nowYear, lastMonth, 1);
return this.formatDate(lastMonthStartDate);
} //获得上月结束时间
public getLastMonthEndDate(){
this.addTiem();
let lastMonthDate = new Date(); //上月日期
lastMonthDate.setDate(1);
lastMonthDate.setMonth(lastMonthDate.getMonth() - 1);
let lastYear = lastMonthDate.getFullYear();
let lastMonth = lastMonthDate.getMonth(); let lastMonthEndDate = new Date(this.nowYear, lastMonth, this.getMonthDays(lastMonth));
return this.formatDate(lastMonthEndDate);
} //获得本季度的开始日期
public getQuarterStartDate(){
this.addTiem();
let quarterStartDate = new Date(this.nowYear, this.getQuarterStartMonth(), 1);
return this.formatDate(quarterStartDate);
} //或的本季度的结束日期
public getQuarterEndDate(){
this.addTiem();
let quarterEndMonth = this.getQuarterStartMonth() + 2;
let quarterStartDate = new Date(this.nowYear, quarterEndMonth, this.getMonthDays(quarterEndMonth));
return this.formatDate(quarterStartDate);
}
}

  

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. Memcached 快速入门

    Memcached简介 Memcached是一个专门用来做缓存的服务器,而且缓存的数据都在内存中.Memcached就相当于一个Dictionary键值对集合,保存的是键值对,然后根据key取valu ...

  2. 解决response.setHeader("Content-disposition" 中文乱码问题

    Content-Disposition中文乱码 Response.setHeader(”Content-Disposition”, “attachment; filename=” + fileName ...

  3. Typescript知识梳理

    概述 TypeScript简称TS,具有类型系统,且是JavaScript的超集. 它可以编译成普通的JavaScript代码.TypeScript支持任意浏览器,任意环境,任意系统并且是开源的.通过 ...

  4. JS获取地址栏的参数值

    function GetQueryString(name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)( ...

  5. python之集合set

    1.测试 # python2和python3方法列表相同 ops23 = ['add', 'clear', 'copy', 'difference', 'difference_update', 'di ...

  6. Migrating your code from 9.3 to 10.x

    刚发现ArcGIS Objects SDK提供了一个代码升级分析工具,用于辅助将程序从9.3升级到10.X:ArcGIS Code Migration Analyzer. 安装sdk后,在vs2010 ...

  7. gitlab之五: gitlab之webhook

    webhook(网络钩子),一般与jenkins联合使用,gitlab的某个项目的代码更新了后就触发 webhook中配置的 url ,这个url一般是某一个jienkins中某一个job的url.即 ...

  8. 2018牛客网暑假ACM多校训练赛(第二场)E tree 动态规划

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round2-E.html 题目传送门 - 2018牛客多校赛第二场 E ...

  9. Kafka-API

    ctrl+Hnew 它的实现类ctrl+r替换格式化ctrl+alt+l ctrl+fctrl+alt+v 替换 &lt " &lt < &gt > Ka ...

  10. 【官档整理】Visual Studio 2017 VS2017 中文离线安装包下载

    [官档整理]Visual Studio 2017 VS2017 中文离线安装包下载 转 https://blog.csdn.net/fromfire2/article/details/81104648 ...