最近有个统计分布的需求,需要按统计本周,上周,本月,上月,本季度,上季度,本年度,上年度等时间统计分布趋势,所以这里就涉及到计算周,月,季度,年度等的起止时间了,下面总结一下C#中关于根据当前时间获取周,月,季度,年度等时间段的起止时间的方法,废话不多说,直接贴代码,如果你觉得有用,请多多推荐. DateTime dt = DateTime.Now; //当前时间 DateTime startWeek = dt.AddDays( - Convert.ToInt32(dt.DayOfWeek.To…
DateTime dt = DateTime.Now; //当前时间 DateTime startWeek = dt.AddDays(1 - Convert.ToInt32(dt.DayOfWeek.ToString("d"))); //本周周一 DateTime endWeek = startWeek.AddDays(6); //本周周日 DateTime startMonth = dt.AddDays(1 - dt.Day); //本月月初 DateTime endMonth =…
DateTime dt = DateTime.Now; //当前时间 DateTime startWeek = dt.AddDays( - Convert.ToInt32(dt.DayOfWeek.ToString("d"))); //本周周一 DateTime endWeek = startWeek.AddDays(); //本周周日 DateTime startMonth = dt.AddDays( - dt.Day); //本月月初 DateTime endMonth = sta…
# 时间## 时间和周数 import time import datetime # 获取今天是第几周 print(time.strftime('%W')) # 获取当前是周几(0-6,0代表周一) today=datetime.datetime.now().weekday() # 获取指定日期属于当年的第几周 week=datetime.datetime.strptime(','%Y%m%d').strftime('%W') ## 获取下周的时间范围 import datetime,calen…
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * Created by xiaochun on 2016/3/24. */ public class TimeUtil { public static void main(String[] args) { System.out.println("当前小时开始:"+getCurrentHourStartTime…
/** * 针对时间的工具类 */ var DateTimeUtil = function () { /*** * 获得当前时间 */ this.getCurrentDate = function () { return new Date(); }; /*** * 获得本周起止时间 */ this.getCurrentWeek = function () { //起止日期数组 var startStop = new Array(); //获取当前时间 var currentDate = this…
Date类 Date类的大多数构造函数和方法都已经抛弃,只留下和毫秒有关的操作,目前常用的构造函数 常用方法 设置毫秒数 读取毫秒数 toString()打印结果 //创建日期对象,把当前的毫秒值转成日期对象 Date date = new Date(1607616000000L); System.out.println(date); //打印结果:Fri Dec 11 00:00:00 CST 2020 DateFormate类格式化日期 DateFormat 是日期/时间格式化子类的抽象类,…
var getCurrentWeek = function (day) { var days = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; //定义数组 var week = []; //获取当前星期X(0-6,0代表星期天) var index = new Date(day).getDay(); //循环 for (va…
获取周的第一天,最后一天 System.out.println(getStartEndDate("2016-05-01", 1)); 获取星期的第一天和最后一天 System.out.println(getStartEndDate("2016-05-01", 0));   public static String getStartEndDate(String aDay, int type) { SimpleDateFormat df = new SimpleDate…
C/C++中怎样获取日期和时间摘要:  本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的数据结构和函数,并对计时.时间的获取.时间的计算和显示格式等方面进行了阐述.本文还通过大量的实例向你展示了time.h头文件中声明的各种函数和数据结构的详细使用方法. 关键字:UTC(世界标准时间),Calendar Time(日历时间),epoch(时间点),clock tick(时钟计时单元) 1.概念  在C/C++中,对字符串的操作有很多值得注意的问题,同样,C/C++对时间的操作…