date

PHP获取当前月份的前一个月、后一个月

此生再无相见时 提交于 2020-04-07 11:36:08
在某次开发中,需要对月份进行处理,获取到前一个月或者后一个月,开始使用 date("Ym", strtotime("-1 month")) 后来发现,这种方法会有问题,在月份有31天的时候,比如7月31日,会出现 date("Ym", strtotime("-1 month")) 这个是时间也是201207与date("Ym")结果一样。这样就会导致在这天产生很多问题。 后来只能用这样 的方法 Php代码 function GetMonth($sign="1") { //得到系统的年月 $tmp_date=date("Ym"); //切割出年份 $tmp_year=substr($tmp_date,0,4); //切割出月份 $tmp_mon =substr($tmp_date,4,2); $tmp_nextmonth=mktime(0,0,0,$tmp_mon+1,1,$tmp_year); $tmp_forwardmonth=mktime(0,0,0,$tmp_mon-1,1,$tmp_year); if($sign==0){ //得到当前月的下一个月 return $fm_next_month=date("Ym",$tmp_nextmonth); }else{ //得到当前月的上一个月 return $fm_forward_month=date("Ym",$tmp

How can I manipulate a date field in an aggregation pipeline?

筅森魡賤 提交于 2020-04-07 10:30:45
问题 I'm trying to set the time from a Date field to the start of the day function getDate(date){ return new Date(date.getYear(), date.getMonth(), date.getDate(), 0,0,0); } ... {"$project" : { "_id" : getDate("$dt"), ... If I send "$dt" I get TypeError: date.getYear is not a function as I'm passing a string, If remove the quotation marks, I get Error: "$dt is not defined" , but if I set "$dt" as value for "_id" I get a correct ISO Date. So how do I pass the date object to the function? 回答1:

How can I manipulate a date field in an aggregation pipeline?

让人想犯罪 __ 提交于 2020-04-07 10:30:36
问题 I'm trying to set the time from a Date field to the start of the day function getDate(date){ return new Date(date.getYear(), date.getMonth(), date.getDate(), 0,0,0); } ... {"$project" : { "_id" : getDate("$dt"), ... If I send "$dt" I get TypeError: date.getYear is not a function as I'm passing a string, If remove the quotation marks, I get Error: "$dt is not defined" , but if I set "$dt" as value for "_id" I get a correct ISO Date. So how do I pass the date object to the function? 回答1:

设计模式-组合模式

╄→гoц情女王★ 提交于 2020-04-07 07:50:07
组合模式(Composite Pattern)也叫合成模式,有时又叫做部分-整体模式(Part-Whole), 主要是用来描述部分与整体的关系: 定义: Compose objects into tree structures to represent part-whole hierarchies.Composite lets clients treat individual objects and compositions of objects uniformly.(将对象组合成树形结构以表示“部分-整体”的层次结构,使得用户对单个对象和组合对象的使用具有一致性。) 举个最常见的例子,公司组织架构就是一个典型的树状结构(网上截取图): image.png 我们一般会这样设计组织架构,看代码实现 首先根节点IROOT /** * 根节点 * @author shuliangzhao * @Title: IRoot * @ProjectName design-parent * @Description: TODO * @date 2019/6/18 22:37 */ public interface IRoot { //得到总经理的信息 public String getInfo(); //总经理下边要有小兵,那要能增加小兵,比如研发部总经理,这是个树枝节点 public void

Swift date(byAdding:to:) returns nil for trivial calculation in REPL

南楼画角 提交于 2020-04-07 06:52:21
问题 I expect this to return a Date object representing the time one hour from now: Calendar.current.date(byAdding: DateComponents(hour: 1), to: Date()) However it returns nil . This seems like a rather straightforward use of the API so perhaps I have some fundamental misconception about how this API should work? This only appears to affect the swift command line REPL included with Xcode (version 11.3.1 on macOS Catalina 10.15.3). Interestingly, wrapping the above code in a print() call forces it

java之Date(日期)、Date格式化、Calendar(日历)

时光怂恿深爱的人放手 提交于 2020-04-07 05:45:34
参考 http://how2j.cn/k/date/date-date/346.html Date(日期) Date类 注意:是 java.util.Date; 而非 java.sql.Date,此类是给数据库访问的时候使用的 时间原点概念 所有的数据类型,无论是整数,布尔,浮点数还是字符串,最后都需要以数字的形式表现出来。 日期类型也不例外,换句话说,一个日期,比如2020年10月1日,在计算机里,会用一个数字来代替。 那么最特殊的一个数字,就是零. 零这个数字,就代表Java中的时间原点,其对应的日期是1970年1月1日 8点0分0秒 。 (为什么是8点,因为中国的太平洋时区是UTC-8,刚好和格林威治时间差8个小时) 为什么对应1970年呢? 因为1969年发布了第一个 UNIX 版本:AT&T,综合考虑,当时就把1970年当做了时间原点。 所有的日期,都是以为这个0点为基准,每过一毫秒,就+1。 创建日期对象 package date; // import java.util.Date; public class TestDate { public static void main(String[] args) { // 当前时间 Date d1 = new Date(); System.out.println("当前时间:"); System.out.println(d1

java.time.format.DateTimeParseException for dd-MMM-yyyy format [duplicate]

荒凉一梦 提交于 2020-04-07 02:55:14
问题 This question already has answers here : How to parse case-insensitive strings with jsr310 DateTimeFormatter? (3 answers) Closed 4 years ago . I am trying to parse date of dd-MMM-yyyy format. package com.company; import javax.swing.text.DateFormatter; import java.time.format.DateTimeFormatter; import java.time.*; import java.util.Locale; public class Main { public static void main(String[] args) { // write your code here MonthDay m; Locale.setDefault(Locale.ENGLISH); DateTimeFormatter dTF =

VBScript formatting dd/mm/yyyy the values contained in cell Excel file [duplicate]

≡放荡痞女 提交于 2020-04-07 02:28:25
问题 This question already has an answer here : Format current date and time in VBScript (1 answer) Closed 11 days ago . I use this code for import in XLSX Excel file the TXT text file : Set objExcel = CreateObject("Excel.Application") objExcel.Visible = False objExcel.DisplayAlerts = False objExcel.Workbooks.OpenText strTXTfile, , , xlDelimited, , , , , , , True, ";" Set wb = objExcel.ActiveWorkbook objExcel.Sheets(1).Columns("H:H").NumberFormat = "dd/mm/yyyy" wb.SaveAs strXLSfile,

VBScript formatting dd/mm/yyyy the values contained in cell Excel file [duplicate]

时光毁灭记忆、已成空白 提交于 2020-04-07 02:26:19
问题 This question already has an answer here : Format current date and time in VBScript (1 answer) Closed 11 days ago . I use this code for import in XLSX Excel file the TXT text file : Set objExcel = CreateObject("Excel.Application") objExcel.Visible = False objExcel.DisplayAlerts = False objExcel.Workbooks.OpenText strTXTfile, , , xlDelimited, , , , , , , True, ";" Set wb = objExcel.ActiveWorkbook objExcel.Sheets(1).Columns("H:H").NumberFormat = "dd/mm/yyyy" wb.SaveAs strXLSfile,

String.format()用法

懵懂的女人 提交于 2020-04-07 02:12:08
名称 说明 Format(String, Object) 将指定的 String 中的格式项替换为指定的 Object 实例的值的文本等效项。 Format(String, array<>[]()[]) 将指定 String 中的格式项替换为指定数组中相应 Object 实例的值的文本等效项。 Format(IFormatProvider, String, array<>[]()[]) 将指定 String 中的格式项替换为指定数组中相应 Object 实例的值的文本等效项。指定的参数提供区域性特定的格式设置信息。 Format(String, Object, Object) 将指定的 String 中的格式项替换为两个指定的 Object 实例的值的文本等效项。 Format(String, Object, Object, Object) 将指定的 String 中的格式项替换为三个指定的 Object 实例的值的文本等效项。 多个参数 int m[]=new int{a,b,c,d}; string.format("{0}{1}{2}",m); 一个参数 private const string _extraClause = " AND C_INTERNSHIPORG_INTERNSHIPID = {0}"; //将MyCrypt.Decrypt(Request["id"]