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. Senparc.Weixin微信开发(3) 自定义菜单与获取用户组

    自定义菜单 代码参考:http://www.cnblogs.com/szw/p/3750517.html 还可以使用他们官网的自定义:https://neuchar.senparc.com/User/ ...

  2. How to trigger an Animation when TextBlock’s Text is changed during a DataBinding

    原文:http://michaelscherf.wordpress.com/2009/02/23/how-to-trigger-an-animation-when-textblocks-text-is ...

  3. Codeforces 1139F Dish Shopping 树状数组套平衡树 || 平衡树

    Dish Shopping 将每个物品拆成p 和 s 再加上人排序. 然后问题就变成了, 对于一个线段(L - R), 问有多少个(li, ri)满足  L >= li && R ...

  4. Ubuntu学习

    一. Ubuntu简介 Ubuntu(乌班图)是一个基于Debian的以桌面应用为主的Linux操作系统,据说其名称来自非洲南部祖鲁语或科萨语的“ubuntu”一词,意思是“人性”.“我的存在是因为大 ...

  5. Android测试环境搭建

    Android测试环境搭建 一.操作系统 使用Win7_64位操作系统.(可以用其他的系统,下面都是针对Win7 64位进行操作) 二.安装JDK 运行jdk-6u45-windows-x64.exe ...

  6. P1087 FBI树 二叉树

    题目描述 我们可以把由“00”和“11”组成的字符串分为三类:全“00”串称为BB串,全“11”串称为I串,既含“00”又含“11”的串则称为F串. FBIFBI树是一种二叉树,它的结点类型也包括FF ...

  7. 12306登录爬虫 session版本

    import requests import re import base64 # 定义session headers = { 'User-Agent':'Mozilla/5.0 (Windows N ...

  8. 爬虫3 requests基础之下载图片用content(二进制内容)

    res = requests.get('http://soso3.gtimg.cn/sosopic/0/11129365531347748413/640') # print(res.content) ...

  9. Java大数相加(多个大数相加)-hdu1250

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 题目描述: 题目大意是:已知一个Hat's Fibonacci序列,该序列满足F(1) = 1, ...

  10. ACM-ICPC Beijing 2016 Genius ACM(倍增+二分)

    描述 给定一个整数 M,对于任意一个整数集合 S,定义“校验值”如下: 从集合 S 中取出 M 对数(即 2∗M 个数,不能重复使用集合中的数,如果 S 中的整 数不够 M 对,则取到不能取为止),使 ...