datetime-format

`datetime.strftime` and `datetime.strptime` interprete %Y differently

人走茶凉 提交于 2019-12-07 03:09:58
问题 I use a statement as shown below to create a datetime object from a string: t = datetime.strptime("0023-10-10", "%Y-%m-%d") Later, somewhere in my code uses the t object and invoke the strftime method with the same format string: t.strftime("%Y-%m-%d") This causes a ValueError: year=23 is before 1900; the datetime strftime() methods require year >= 1900 . It seems that the validation of the %Y input is different in this two similar methods. So I have to do the following to make sure I don't

Convert DateTime from English to Spanish

时光总嘲笑我的痴心妄想 提交于 2019-12-07 00:59:15
问题 Does anybody know how to convert a DateTime from English to Spanish? E.g convert: Monday, January 01, 2011 into Lunes, Enero 01, 2011 ??? Thanks in advance. 回答1: Yyou can use CultureInfo to do this, if you set the current culture in the running thread the date will format in the correct culture http://msdn.microsoft.com/en-us/library/5hh873ya.aspx in vb.net Dim TheDate As DateTime = DateTime.Parse("January 01 2011") Thread.CurrentThread.CurrentCulture = New CultureInfo("es-ES") MsgBox(TheDate

how to achieve timespan to string conversion?

那年仲夏 提交于 2019-12-06 22:52:46
问题 I tried searching here, but it couldn't help me much .. I want to convert time_span to string, I don't want to return the timespan in days .. but only HH:mm:ss. How to achieve that? My sample code is here: String time_span_par = "06:12:40"; String time_str = "18:13:59"; TimeSpan time_span_var = TimeSpan.Parse(time_span_par); TimeSpan time_span = TimeSpan.Parse(time_str); time_span = time_span.Add(time_span_var); string temp = time_span.ToString("HH:mm:ss"); 回答1: Try using DateTime d = new

DateTime format in c# [duplicate]

一曲冷凌霜 提交于 2019-12-06 16:46:14
This question already has answers here : Closed 8 years ago . Possible Duplicate: Format date in C# I want to display the date in the format May 16, 2011 . I have used format String.Format("{0:D}" by which i got the output like Monday, May 16, 2011 . So please any one tell me how i will be able to show date time in the following format May 16, 2011 Thanks in advance Daniel A. White "{0:MMMM d, yyyy}" Here is the documentation. Custom Date and Time Format Strings DateTime dt = DateTime.Now; String.Format("{0:MMMM d, yyyy}", dt); This should to the trick? EDIT: Here are some handy examples! http

date format in d3, would like to have month as an integer instead of decimal

♀尐吖头ヾ 提交于 2019-12-06 11:22:20
I would like to have format as 6/19 instead of 06/19 for my X axis. It does not seem to provide a way of doing so on its official documentation: https://github.com/mbostock/d3/wiki/Time-Formatting Any clues? Thanks? See the part about padding: The % sign indicating a directive may be immediately followed by a padding modifier: 0 - zero-padding _ - space-padding - - disable padding For example, "%-m/%-d" will disable padding for both the month and date, giving you "6/1" for June 1st, as opposed to "%m/%d" which gives "06/01". 来源: https://stackoverflow.com/questions/16681038/date-format-in-d3

Is DateTime.parse() in Ruby dependent on locale?

旧城冷巷雨未停 提交于 2019-12-06 10:34:47
I'm wondering regarding the output of the following example: when parsing 01/03 , will it be resolved as Mar, 1st or Jan, 3rd ? Ruby is not locale dependent. Because Ruby is a server-side language and not a client-side language like JavaScript, Ruby uses the system clock from your web app server - and uses this information to calculate the time. Whatever timezone you have your system set to is what your Ruby app will use. When parsing a date from a string, DateTime will make its best guess based on how the input is formatted: DateTime.parse('01/03') #=> Thu, 03 Jan 2019 00:00:00 +0000 DateTime

WCF REST JSON with ISO Date Format

╄→гoц情女王★ 提交于 2019-12-06 08:51:24
I got into a big problem supporting ISO dateformat with JSON in my WCF Web service ( Framework 4.0 ). I tried a lot, but no luck yet. Rest Service : [WebInvoke(Method = "PUT", UriTemplate = "/{mvnoid}/{OrderID}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] public DataContracts.Feedback InsertOrder(string mvnoid,string OrderID,OrderRequest orderRequest) { OrderRequestManager orderProcessor = new OrderRequestManager(); DataContracts.Feedback feedback = orderProcessor.ProcessOrder(orderRequest); return feedback; } This is my object: [DataContract(Namespace =

Qt seconds to DD HH SS

孤人 提交于 2019-12-06 07:27:51
using Qt 4.8 how can I print the time in the format DD HH SS? I have the seconds and I want to get back a string in that format. cor3ntin QDateTime::fromTime_t(seconds).toString("ss hh DD"); see http://qt-project.org/doc/qt-5.0/qdatetime.html#toString If you want a duration ( your question was really unclear) try something like : QString seconds_to_DHMS(quint32 duration) { QString res; int seconds = (int) (duration % 60); duration /= 60; int minutes = (int) (duration % 60); duration /= 60; int hours = (int) (duration % 24); int days = (int) (duration / 24); if((hours == 0)&&(days == 0)) return

Add the current time to a DateTime?

怎甘沉沦 提交于 2019-12-06 06:27:22
问题 I have a string which represents a date, its given back from a DropDownList. The string is "27.08.2010" for example. Now I want to add the current time to this and parse it to Datetime ... so in the end it should be a DateTime like 27.08.2010 15:12:45 for example. How could I do this? Right now, I am putting together a string using DateTime.Now.Hour etc. and make a DateTime out of it, but that seems to be the wrong way. Thanks :) 回答1: string s = "27.08.2010"; DateTime dt = DateTime.ParseExact

How to print calendar in monthwise matrix format in Python 3.6?

情到浓时终转凉″ 提交于 2019-12-06 06:20:25
I have created the Indian National calendar function in Python as below, import calendar import datetime 'Days in Tamil names. first day start from 0-Monday and 6- sunday. similar to ISO format' tamil_day = ('திங்கள்','செவ்வாய்','புதன்','வியாழன்','வெள்ளி','சனி','ஞாயிறு') 'months in Tamil names. first month start from 0-Chithirai and 11-panguni. similar to ISO format' tamil_months = ('சித்திரை','வைகாசி','ஆணி','ஆடி','ஆவணி','புரட்டாசி','ஐப்பசி','கார்த்திகை','மார்கழி','தை','மாசி','பங்குனி') '''reference date for Indian Saka Era Saka Era 1876 is equal to 1954-55AD or Saka 1875-76 is equal to 1954