datetime-format

In an ISO 8601 date, is the T character mandatory?

跟風遠走 提交于 2019-12-18 11:45:17
问题 I'm wondering if the following date is ISO8601 compliant : 2012-03-02 14:57:05.456+0500 (for sure, 2012-03-02T14:57:05.456+0500 is compliant, but not that much human readable !) IOW, is the T between date and time mandatory ? 回答1: It's required unless the "partners in information interchange" agree to omit it. Quoting the ISO 8601 standard, section 4.3.2: The character [T] shall be used as time designator to indicate the start of the representation of the time of day component in these

How to convert the integer date format into YYYYMMDD?

删除回忆录丶 提交于 2019-12-18 05:43:13
问题 Python and Matlab quite often have integer date representations as follows: 733828.0 733829.0 733832.0 733833.0 733834.0 733835.0 733836.0 733839.0 733840.0 733841.0 these numbers correspond to some dates this year. Do you guys know which function can convert them back to YYYYMMDD format? thanks a million! 回答1: The datetime.datetime class can help you here. The following works, if those values are treated as integer days (you don't specify what they are). >>> from datetime import datetime >>>

How to convert the integer date format into YYYYMMDD?

偶尔善良 提交于 2019-12-18 05:41:42
问题 Python and Matlab quite often have integer date representations as follows: 733828.0 733829.0 733832.0 733833.0 733834.0 733835.0 733836.0 733839.0 733840.0 733841.0 these numbers correspond to some dates this year. Do you guys know which function can convert them back to YYYYMMDD format? thanks a million! 回答1: The datetime.datetime class can help you here. The following works, if those values are treated as integer days (you don't specify what they are). >>> from datetime import datetime >>>

How to serialize and deserialize Java 8's java.time types with Gson? [closed]

∥☆過路亽.° 提交于 2019-12-18 03:04:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm using GSON to serialise some object graphs to JSON. These objects graphs use the new Java 8 java.time entities ( ZonedDateTime , OffsetDateTime , LocalTime etc). I've found a library for Joda Time serialisers here - is there an equivalent library for the JDK java.time classes? (This person had no luck with

How parse 2013-03-13T20:59:31+0000 date string to Date

我们两清 提交于 2019-12-18 02:39:29
问题 How to parse this format date string 2013-03-13T20:59:31+0000 to Date object? I'm trying on this way but it doesn't work. DateFormat df = new SimpleDateFormat("YYYY-MM-DDThh:mm:ssTZD"); Date result = df.parse(time); 回答1: DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ"); Year is lower case y. Any characters that are in the input which are not related to the date (like the 'T' in 2013-03-13T20:59:31+0000 should be quoted in '' . For a list of the defined pattern letters see the

Unable to set datetime format in MVC 4 using data annotations

别来无恙 提交于 2019-12-17 23:25:32
问题 I will try everything but not working this( dd/MM/yyyy ) date format, this always gate mm/dd/yyyy [Display(Name = "Release Date")] [DataType(DataType.DateTime)] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")] public Nullable<DateTime> release_date { get; set; } Razor view @Html.EditorFor(model => model.release_date) Using DateTime Template. @model Nullable<System.DateTime> @if (Model.HasValue) { @Html.TextBox("", String.Format("{0:dd/MM/yyyy}", Model.Value))

How to convert date from yyyyMMdd format to mm-dd-yyyy format

感情迁移 提交于 2019-12-17 19:12:32
问题 I want to convert a string which contains the date in yyyyMMdd format to mm-dd-yyyy DateTime format. How do I get it? 回答1: var dateString = "20050802"; var date = myDate = DateTime.ParseExact(dateString, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture); 回答2: public static DateTime ConvertDate(string date, string pattern) { DateTime retval = DateTime.MinValue; if (System.DateTime.TryParseExact(date, pattern, System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None,

Why is datetime.strptime not working in this simple example?

大兔子大兔子 提交于 2019-12-17 17:53:19
问题 I'm using strptime to convert a date string into a datetime . According to the linked page, formatting like this should work: >>> # Using datetime.strptime() >>> dt = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M") My code is: import datetime dtDate = datetime.strptime(sDate,"%m/%d/%Y") where sDate = "07/27/2012" . (I understand, from the same page, that %Y is "Year with century as a decimal number." ) I have tried putting the actual value of sDate into the code: dtDate = datetime

Java LocalDate Formatting of 2000-1-2 error [duplicate]

自作多情 提交于 2019-12-17 17:12:29
问题 This question already has answers here : Java string to date conversion (13 answers) SimpleDateFormat incorrectly rolling year forward during format of Date [duplicate] (2 answers) Closed last year . Today some tests on a new build machine failed, where on other machines thes where ok. Looking after the problem it shows that @Test public void testDateTimeFormater() { String result = LocalDate.of(2000,1,2) .format(DateTimeFormatter.ofPattern("YYYY-MM-dd")); Assert.assertTrue(result,result

python strptime format with optional bits

余生长醉 提交于 2019-12-17 16:24:23
问题 Right now I have: timestamp = datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S.%f') This works great unless I'm converting a string that doesn't have the microseconds. How can I specify that the microseconds are optional (and should be considered 0 if they aren't in the string)? 回答1: You could use a try/except block: try: timestamp = datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S.%f') except ValueError: timestamp = datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S') 回答2: What about just