date-manipulation

Python datetime - setting fixed hour and minute after using strptime to get day,month,year

倖福魔咒の 提交于 2019-12-03 01:23:36
问题 I've successfully converted something of 26 Sep 2012 format to 26-09-2012 using: datetime.strptime(request.POST['sample_date'],'%d %b %Y') However, I don't know how to set the hour and minute of something like the above to 11:59. Does anyone know how to do this? Note, this can be a future date or any random one, not just the current date. 回答1: Use datetime.replace: from datetime import datetime date = datetime.strptime('26 Sep 2012', '%d %b %Y') newdate = date.replace(hour=11, minute=59) 回答2:

Python datetime - setting fixed hour and minute after using strptime to get day,month,year

假如想象 提交于 2019-12-02 14:46:09
I've successfully converted something of 26 Sep 2012 format to 26-09-2012 using: datetime.strptime(request.POST['sample_date'],'%d %b %Y') However, I don't know how to set the hour and minute of something like the above to 11:59. Does anyone know how to do this? Note, this can be a future date or any random one, not just the current date. Use datetime.replace : from datetime import datetime date = datetime.strptime('26 Sep 2012', '%d %b %Y') newdate = date.replace(hour=11, minute=59) Abhay Chauhan datetime.replace() will provide the best options. Also, it provides facility for replacing day,

How to merge date and time as a datetime in Google Apps Spreadsheet script?

筅森魡賤 提交于 2019-11-28 08:32:51
问题 I've a Date column in 'dd/mm/yyyy' format and Time column in 'HH:MM AM/PM' format in Google App spreadsheet. In app script, I want to join these 2 values as a datetime. How can I do this? Example- date : 13/12/2010, time : 4:30 PM Then I want to get a combined value like '13/12/2010 4:30 PM' as a datetime object. I tried to parse date and time separately using getYear, getDay JS functions. And created a new date using new Date(year, month, day, hours, minutes) But for some reason time '4:30'

Start and end date of a current month

自古美人都是妖i 提交于 2019-11-27 11:54:20
I need the start date and the end date of the current month in Java. When the JSP page is loaded with the current month it should automatically calculate the start and end date of that month. It should be irrespective of the year and month. That is some month has 31 days or 30 days or 28 days. This should satisfy for a leap year too. Can you help me out with that? For example if I select month May in a list box I need starting date that is 1 and end date that is 31. There you go: public Pair<Date, Date> getDateRange() { Date begining, end; { Calendar calendar = getCalendarForNow(); calendar

Compare two dates Google apps script

痴心易碎 提交于 2019-11-27 09:04:15
What would be the best way to compare two dates ? var int = e.parameter.intlistbox; var startDate = rSheet.getRange(parseInt(int) + 1 ,1).getValues(); // returns Sat Jun 30 2012 00:00:00 GMT-0300 (BRT) var toDay = new Date(); // Sat Jun 23 2012 22:24:56 GMT-0300 (BRT) if (startDate > toDay){ .... I saw the .toString() option but that seems to work only for == or === operator. Anything clear about this matter? The Date object has the valueOf method which returns the number of milliseconds since midnight 1970-01-01. You can use it to compare dates. Something like var date01 = new Date(); var

Compare two dates Google apps script

狂风中的少年 提交于 2019-11-26 14:21:55
问题 What would be the best way to compare two dates ? var int = e.parameter.intlistbox; var startDate = rSheet.getRange(parseInt(int) + 1 ,1).getValues(); // returns Sat Jun 30 2012 00:00:00 GMT-0300 (BRT) var toDay = new Date(); // Sat Jun 23 2012 22:24:56 GMT-0300 (BRT) if (startDate > toDay){ .... I saw the .toString() option but that seems to work only for == or === operator. Anything clear about this matter? 回答1: The Date object has the valueOf method which returns the number of milliseconds

Simplest way to increment a date in PHP?

天涯浪子 提交于 2019-11-26 05:29:28
问题 Say I have a string coming in, \"2007-02-28\" , what\'s the simplest code I could write to turn that into \"2007-03-01\" ? Right now I\'m just using strtotime() , then adding 24*60*60 , then using date() , but just wondering if there is a cleaner, simpler, or more clever way of doing it. 回答1: A clean way is to use strtotime() $date = strtotime("+1 day", strtotime("2007-02-28")); echo date("Y-m-d", $date); Will give you the 2007-03-01 回答2: It's cleaner and simpler to add 86400. :) The high

How to add 30 minutes to a JavaScript Date object?

梦想与她 提交于 2019-11-25 21:59:24
问题 I\'d like to get a Date object which is 30 minutes later than another Date object. How do I do it with JavaScript? 回答1: Using a Library If you are doing a lot of date work, you may want to look into JavaScript date libraries like Datejs or Moment.js. For example, with Moment.js, this is simply: var newDateObj = moment(oldDateObj).add(30, 'm').toDate(); Vanilla Javascript This is like chaos's answer, but in one line: var newDateObj = new Date(oldDateObj.getTime() + diff*60000); Where diff is