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. Linux SSH & SCP命令

    SSH SSH为建立在应用层和传输层基础上的安全协议 sshd服务使用SSH协议进行远程控制,或在计算机之间传送文件.而实现此功能的telnet(远程桌面) 是不安全的,使用明文传送密码 ssh ss ...

  2. TFS 生成任务报错:目录不是空的

    转到代理目录下,将生成文件夹清空,重新启动生成任务即可

  3. C#学习-面向对象语言都有类

    面向对象语言的一个基本特征是它们都有类,类是C#(这类语言)中的一种复杂数据类型. 类代表一组具有公共属性和行为的对象. 在C#中定义一个类是非常简单的,只需使用class关键字并按格式来定义即可. ...

  4. Git坑换行符自动转换 [转载]

    转自https://www.cnblogs.com/zjoch/p/5400251.html 源起 一直想在 GitHub 上发布项目.参与项目,但 Git 这货比较难学啊.买了一本<Git 权 ...

  5. [转] UniCode编码表

    Unicode编码则是采用双字节16位来进行编号,可编65536字符,基本上包含了世界上所有的语言字符,它也就成为了全世界一种通用的编码,而且用十六进制4位表示一个编码,非常简结直观,为大多数开发者所 ...

  6. es6 模板字符串

    模板字符串 提供构造字符串的语法糖,在 Prel/python 等语言中也都有类似特性. 1.反引号模板,可以换行 2.反引号模板,可以嵌套 用+``来嵌套 好处:语法更加简洁 var name=&q ...

  7. gcc make 与cmake

    1. gcc (1)是什么? 它是GNU Compiler Collection(就是GNU编译器套件),也可以简单认为是编译器.它可以编译很多种编程语言(括C.C++.Objective-C.For ...

  8. vscode git

    Git 全局设置: git config --global user.name "xxxx" git config --global user.email "123456 ...

  9. 根据关键字找进程id

    #!/usr/bin/pythonimport subprocessimport sysimport loggingimport os gameproc = "jd_5.py" d ...

  10. Python题目练习(二)

    1.如何实现对python列表去重,并保持原来顺序 li = [1,2,5,3,1,6,3,8,0,3,2,4] l = [] for i in li: if i not in l: l.append ...