datetime

Infer year from day of week and date with python datetime

醉酒当歌 提交于 2021-02-09 08:10:21
问题 I have data which is of the form Thu Jun 22 09:43:06 and I would like to infer the year from this to use datetime to calculate the time between two dates. Is there a way to use datetime to infer the year given the above data? 回答1: No, but if you know the range (for example 2010..2017), you can just iterate over years to see if Jun 22 falls on Thursday: def find_year(start_year, end_year, month, day, week_day): for y in range(start_year, end_year+1): if datetime.datetime(y, month, day, 0, 0)

Infer year from day of week and date with python datetime

老子叫甜甜 提交于 2021-02-09 08:08:32
问题 I have data which is of the form Thu Jun 22 09:43:06 and I would like to infer the year from this to use datetime to calculate the time between two dates. Is there a way to use datetime to infer the year given the above data? 回答1: No, but if you know the range (for example 2010..2017), you can just iterate over years to see if Jun 22 falls on Thursday: def find_year(start_year, end_year, month, day, week_day): for y in range(start_year, end_year+1): if datetime.datetime(y, month, day, 0, 0)

Infer year from day of week and date with python datetime

≯℡__Kan透↙ 提交于 2021-02-09 08:05:02
问题 I have data which is of the form Thu Jun 22 09:43:06 and I would like to infer the year from this to use datetime to calculate the time between two dates. Is there a way to use datetime to infer the year given the above data? 回答1: No, but if you know the range (for example 2010..2017), you can just iterate over years to see if Jun 22 falls on Thursday: def find_year(start_year, end_year, month, day, week_day): for y in range(start_year, end_year+1): if datetime.datetime(y, month, day, 0, 0)

Numpy Where Changing Timestamps/Datetime to Integers

谁都会走 提交于 2021-02-08 15:22:22
问题 Not so much a question but something puzzling me. I have a column of dates that looks something like this: 0 NaT 1 1996-04-01 2 2000-03-01 3 NaT 4 NaT 5 NaT 6 NaT 7 NaT 8 NaT I'd like to convert it the NaTs to a static value. (Assume I imported pandas as pd and numpy as np). If I do: mydata['mynewdate'] = mydata.mydate.replace( np.NaN, pd.datetime(1994,6,30,0,0)) All is well, I get: 0 1994-06-30 1 1996-04-01 2 2000-03-01 3 1994-06-30 4 1994-06-30 5 1994-06-30 6 1994-06-30 7 1994-06-30 8 1994

Numpy Where Changing Timestamps/Datetime to Integers

∥☆過路亽.° 提交于 2021-02-08 15:20:08
问题 Not so much a question but something puzzling me. I have a column of dates that looks something like this: 0 NaT 1 1996-04-01 2 2000-03-01 3 NaT 4 NaT 5 NaT 6 NaT 7 NaT 8 NaT I'd like to convert it the NaTs to a static value. (Assume I imported pandas as pd and numpy as np). If I do: mydata['mynewdate'] = mydata.mydate.replace( np.NaN, pd.datetime(1994,6,30,0,0)) All is well, I get: 0 1994-06-30 1 1996-04-01 2 2000-03-01 3 1994-06-30 4 1994-06-30 5 1994-06-30 6 1994-06-30 7 1994-06-30 8 1994

How to check if current time falls within a specific range on a week day using jquery/javascript?

只谈情不闲聊 提交于 2021-02-08 14:13:20
问题 When a user visits a page I need to check if the current time falls between 9:00 am and 5:30pm on a weekday and display something using jquery/javascript.But I am not sure how can check that. Could someone please help? Thanks 回答1: This should hopefully help: function checkTime() { var d = new Date(); // current time var hours = d.getHours(); var mins = d.getMinutes(); var day = d.getDay(); return day >= 1 && day <= 5 && hours >= 9 && (hours < 17 || hours === 17 && mins <= 30); } 回答2: var now

How to check if current time falls within a specific range on a week day using jquery/javascript?

北慕城南 提交于 2021-02-08 14:13:02
问题 When a user visits a page I need to check if the current time falls between 9:00 am and 5:30pm on a weekday and display something using jquery/javascript.But I am not sure how can check that. Could someone please help? Thanks 回答1: This should hopefully help: function checkTime() { var d = new Date(); // current time var hours = d.getHours(); var mins = d.getMinutes(); var day = d.getDay(); return day >= 1 && day <= 5 && hours >= 9 && (hours < 17 || hours === 17 && mins <= 30); } 回答2: var now

as.Date() does not respect POSIXct time zones

大憨熊 提交于 2021-02-08 13:49:12
问题 Okay so here is a subtle "quirk" in the r as.Date function converting from a POSIXct with a timezone, which I am wondering if it is a bug. > as.POSIXct("2013-03-29", tz = "Europe/London") [1] "2013-03-29 GMT" > as.Date(as.POSIXct("2013-03-29", tz = "Europe/London")) [1] "2013-03-29" So far no problem, but..... > as.POSIXct("2013-04-01", tz = "Europe/London") [1] "2013-04-01 BST" > as.Date(as.POSIXct("2013-04-01", tz = "Europe/London")) [1] "2013-03-31" Anybody seen this? Is this a bug or

How to pass date(dd/MM/yyyy HH:mm) as a parameter in REST API

本小妞迷上赌 提交于 2021-02-08 13:41:36
问题 I am trying to write a rest api in which I am passing date as a URL parameter. Date formate is dd/MM/yyyy HH:mm ; REST API URL Is public static final String GET_TestDate = "/stay/datecheck?dateCheckIn={dateCheckIn}"; and Rest Method is @RequestMapping(value = HotelRestURIConstants.GET_TestDate, method = RequestMethod.GET) public @ResponseBody String getDate(@PathVariable("dateCheckIn") @DateTimeFormat(iso= DateTimeFormat.ISO.DATE) String dateCheckIn) { logger.info("passing date as a param");

Does timedelta added to date consider leap year?

十年热恋 提交于 2021-02-08 11:59:30
问题 Example Suppose for a given date, when we add timedelta(days=180), and get the new date, does it consider the leap year and calculate the new date? Or do we exclusively calculate the leap year of the current date whether Feb has 28 / 29 days and get the new date accordingly in python datetime.datetime object? 回答1: Try it out: from datetime import datetime, timedelta dt = datetime(2012, 2, 27) print(dt + timedelta(3)) # March 1st If it didn't handle February 29th, I would expect this to say