egret获取本周,上周,今天,昨天,明天,现在时间,今年,本月
- 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获取本周,上周,今天,昨天,明天,现在时间,今年,本月的更多相关文章
- java获取本周 上周的所有日期
1 根据当前日期获得所在周的日期区间(周一和周日日期) public String getTimeInterval(Date date) { Calendar cal = Calendar.getIn ...
- Asp.net C# 获取本周上周本月上月本年上年第一天最后一天时间大全
DateTime dt = DateTime.Now; int weeknow = Convert.ToInt32(DateTime.Now.DayOfWeek); ) * weeknow + ; D ...
- PHP获取本周的每一天的时间
1.PHP获取未来一周的时间 public function getWeek() { for($i=0;$i<7;$i++) { $arr[$i]=date('Y-m-d',strtotime( ...
- 用php获取本周,上周,本月,上月,本季度日期的代码
echo date("Ymd",strtotime("now")), "\n"; echo date("Ymd",str ...
- js获取本周、上周的开始结束时间
这两天在做一个报表体统,其中涉及到了一个根据本周,上周,本月,上月的时间来进行查询的问题,在这个我就教一下大家怎么实现,大家如果有更好的实现方法的,我也希望大家能说出来,我们交流交流. 首先呢,我写了 ...
- [moka同学笔记]php 获取时间(今天,昨天,三天内,本周,上周,本月,三年内,半年内,一年内,三年内)
<?php /** * php 获取时间(今天,昨天,三天内,本周,上周,本月,三年内,半年内,一年内,三年内) * * author:ihelloworld2010@gmail.com * d ...
- sql server2008 如何获取上月、上周、昨天、今天、本周、本月的查询周期(通过存储过程)
我这边有一个需求要统计订单数据,需要统计订单的上传日期,统计的模块大概是 那么上月.上周.昨天.今天.本周.本月应该是怎样呢? 1.数据分析 因为今天是动态数据,我要查月份(上月.本月),应该是一个日 ...
- java获取当天,前天,明天,本周,本月,本年的开始日期时间和结束日期时间
package demoone; import java.sql.Timestamp; import java.text.ParseException; import java.text.Simple ...
- php日期处理 -- 获取本周和上周的开始日期和结束日期(备忘)
Learn From: http://www.phpernote.com/php-function/1019.html 直接贴代码: <?php header('Content-type: te ...
随机推荐
- 最短路径问题---Dijkstra算法详解
侵删https://blog.csdn.net/qq_35644234/article/details/60870719 前言 Nobody can go back and start a new b ...
- net core 使用 rabbitmq
windows环境安装: https://www.cnblogs.com/ericli-ericli/p/5902270.html .NET Core 使用RabbitMQ https://www.c ...
- 拒绝频繁IP访问--转载
//首先我们要实现 IHttpModule接口 using System; using System.Collections.Generic; using System.Text; using Sys ...
- 关于K8S证书生成方面的脚本草稿
周日在家里计划的. 俺不加班,但在家学习的时间一样没少! 还没弄完,只粗粗弄了etcd证书. #! /usr/bin/env bash set -e set -u set -x THIS_HOST=$ ...
- exception: java.net.ConnectException: Connection refused; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused
1.虽然,不是大错,还说要贴一下,由于我运行run-example streaming.NetworkWordCount localhost 9999的测试案例,出现的错误,第一感觉就是Spark没有 ...
- std::string 是什么
#include "stdafx.h" #include <iostream> #include <string> using std::cout; usi ...
- [转] mongoose学习笔记(超详细)
名词解释 Schema: 一种以文件形式存储的数据库模型骨架,不具备数据库的操作能力 Model: 由Schema编译而成的假想(fancy)构造器,具有抽象属性和行为.Model的每一个实例(ins ...
- 流程图 Graphviz - Graph Visualization Software
0.目录 1.参考 https://www.processon.com/ 应该值得一试 知乎 用什么软件画流程图? 9款国内外垂直领域的在线作图工具[可代替visio] 程序员必知的七个图形工具 说 ...
- Ubuntu14.04创建无线WiFi,android可以连接上网
前提条件: ubuntu14.04 unity,已经通过有线连接到internet 一般环境下创建的wifi热点android设备是无法识别的,网上说通过ap-hotspot方式创建出来的热点手机可以 ...
- RequireJS跨域加载html模版后被转成JS问题分析及解决
问题描述 RequireJS跨域加载HTML模版失败,例如: 在a.com域名下请求CDN域名下的模版,text.js插件会把html文件转成html.js文件去加载,由于并没有生成html.js文件 ...