strftime

Use datetime.strftime() on years before 1900? (“require year >= 1900”)

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I used : utctime = datetime.datetime(1601,1,1) + datetime.timedelta(microseconds = tup[5]) last_visit_time = "Last visit time:"+ utctime.strftime('%Y-%m-%d %H:%M:%S') But I have the time of 1601, so the error show: ValueError: year=1601 is before 1900; the datetime strftime() methods require year >= 1900 I used python2.7, how can I make it? Thanks a lot! 回答1: You can do the following: >>> utctime.isoformat() '1601-01-01T00:00:00.000050' Now if you want to have exactly the same format as above: iso = utctime.isoformat() tokens = iso.strip()

avoiding error from pd.to_datetime in pandas

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a huge dataframe more than 100 mln rows. In that I have a date columns, unfortunately have improper formatted (mixed) date strings. Now I did convert it to datetime by: df['TRX_DATE'] = pd.to_datetime(df['TRX_DATE'],coerce=True) # without any error # Now i want to calculate week day from that date columns df['day_type'] = [x.strftime('%A') for x in d['TRX_DATE']] ###ValueError: month out of range If it would a single field I can manage with dateutil parser. But in this case I am getting out of idea, how to handle that. Just intersted,

Struct timeval to printable format

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Could you please help me how to format a struct timeval instance to human readable format like "2010-01-01 15:35:10.0001"? 回答1: Convert the tv_sec using localtime , and strftime , then append tv_usec part. 回答2: You need to manually append the microseconds part, since it's not in the struct tm that strftime () deals with. Here's a snippet: struct timeval tv; time_t nowtime; struct tm *nowtm; char tmbuf[64], buf[64]; gettimeofday(&tv, NULL); nowtime = tv.tv_sec; nowtm = localtime(&nowtime); strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S",

strftime error while switching my database from sqlite3 to mysql in Rails4

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Recently i changed my database from sqlite3 to mysql.When i ran my project i am getting this error in one of the file which is using this query. date = Date.today + 1 @employees = Employee.where("status = ? AND strftime('%d/%m', date_of_birth) = ?", "Active" , date.strftime('%d/%m') ActionView::Template::Error (Mysql2::Error: FUNCTION hrms_development.strftime does not exist: SELECT COUNT(*) FROM `employees` WHERE (status = 'Active' AND strftime('%d/%m', date_of_birth) = '28/03')): 210: 211: 212: 213: 214: 215: 216: app/views/home/_group

error C4996: 'ctime': This function or variable may be unsafe

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a large project about static source code analysis, and everything compiles successfully, except for one thing. I have provided the error message in the title. The point that confuses me is that it gives an error message saying unsafe. I thought it should be just warning, not an error. By the way, I'm using Visual Studio 2012. Here is the part of the code where I get the error, in ctime. If someone can help me overcome this error, I would be glad. void CppCheckExecutor :: reportProgress ( const std :: string & filename ,

Ruby strftime: Month without leading zero?

时光怂恿深爱的人放手 提交于 2019-12-03 01:47:21
问题 Does Ruby's strftime have a format for the month without a leading zero? I found %e for getting the day without the leading zero, but not having any luck with the month. Ultimately wanting a date formatted like: 9/1/2010 回答1: Some versions of strftime do allow prefixing with minus to format out leading zeros, for eg: strftime "%-d/%-m/%y" However this will depend on strftime on your system. So for consistency I would do something like this instead: dt = Time.local(2010, 'Sep', 1) printf "%d/

Can you format 24-hour time string into 12-hour time string with AM/PM?

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I store some time values in sqlite in %H:%M string format (for example "15:43"), but I would like to get them out formatted in 12 hour format with AM/PM indicators (for example "3:43 PM"). Is this possible with sqlite (and if so, how), or do I need to do this in my application code? 回答1: Unless you extend sqlite with your own custom function , you'll have to do this is code. sqlite's strftime date formatting function only supports a small subset of its C counterpart, insufficient for your problem. sqlite also lacks a selection construct like

Can't convert 'nonetype' object to str implicitly - Python3

匿名 (未验证) 提交于 2019-12-03 00:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Here is my code... from datetime import datetime def userLogin() : Name = input("Please type your Username ") if Name == "User1" : print ("Welcome User1! " + timeIs()) if Name == "User2" : print ("Welcome User2! The time is " + datetime.strftime(datetime.now(), '%H:%M')) if Name == "User3" : print ("Welcome User3! The time is " + datetime.strftime(datetime.now(), '%H:%M')) def timeIs() : print ("The time is " + datetime.strftime(datetime.now(), '%H:%M')) print (userLogin()) As you can see, for User2 and User3 I have set out the full

Can't convert 'nonetype' object to str implicitly - Python3

匿名 (未验证) 提交于 2019-12-03 00:56:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Here is my code... from datetime import datetime def userLogin() : Name = input("Please type your Username ") if Name == "User1" : print ("Welcome User1! " + timeIs()) if Name == "User2" : print ("Welcome User2! The time is " + datetime.strftime(datetime.now(), '%H:%M')) if Name == "User3" : print ("Welcome User3! The time is " + datetime.strftime(datetime.now(), '%H:%M')) def timeIs() : print ("The time is " + datetime.strftime(datetime.now(), '%H:%M')) print (userLogin()) As you can see, for User2 and User3 I have set out the full

PHP strftime outputs wrong format despite correct timezone

点点圈 提交于 2019-12-03 00:29:25
问题 I configured my timezone to Europe/Paris in php.ini. When executing date_default_timezone_get() I do get the correct value. Then, I expect strftime('%x', date()) to output something like 16 novembre 2018 which is the French format. But instead, I get 11/16/2018 which looks like the US format. Any idea why? 回答1: The time zone has no effect on how dates and times are presented, for that you need to set the locale. There are no standards for locale names, but fortunately PHP's setlocale()