datetime-format

Date and time in 24 hours format

强颜欢笑 提交于 2020-01-24 02:19:07
问题 I have a date in this format Fri, 15 Jan 2016 15:14:10 +0800 , and I want to display time like this 2016-01-15 15:14:10 . What I tried is: $test = 'Fri, 15 Jan 2016 15:14:10 +0800'; $t = date('Y-m-d G:i:s',strtotime($test)); echo $t; But it is displaying date in this format: 2016-01-15 7:14:10 , it should be 2016-01-15 15:14:10 . How can i do this? 回答1: Use H instead: $test = 'Fri, 15 Jan 2016 15:14:10 +0800'; $t = date('Y-m-d H:i:s',strtotime($test)); echo $t; H : 24-hour format of an hour

How to parse different string date formats?

我是研究僧i 提交于 2020-01-24 00:34:06
问题 Working on a table with a mix of different strings where it's possible to derive a date. period 0 Q2 '20 Base 1 Q3 '20 Base 2 Q1 '21 Base 3 February '20 Base 4 March '20 Peak 5 Summer 22 Base 6 Winter 20 Peak 7 Summer 21 Base 8 Year 2021 9 October '21 Peak I'd like to be able to parse this into a timestamp for analysis in python. First, ideally I want to parse into 4 new columns 1) day 2) month 3) quarter 4) year. Then use these columns to make a datetime (DD-MM-YYYY). period day month

Localdate: format with locale

喜欢而已 提交于 2020-01-23 06:53:08
问题 I'm attempting to format a LoacalDate but I didn't find any information. I need to format to another language. The case is simply I want to get the month of the year in Spanish. I'm trying to use: Locale locale = new Locale("es", "ES"); But I don't find a SimpleDateFormat or similar to the format LocalDate. LocalDate.now().getMonth(); Can anyone help me? 回答1: Sorry, I used the older (and still more commonly used) date time classes of Java, as you spoke about SimpleDateFormat which is part of

How to Convert JSON Date Format to Simple Date Format? [duplicate]

Deadly 提交于 2020-01-17 18:02:44
问题 This question already has answers here : how to convert incoming Json date into java date format? (2 answers) Closed 2 years ago . I am receiving response of Date in JSON format like /Date(1521866513877+0530)/ which I want in format like this 24/03/2018 10:11:53 . 回答1: If there's no native way to parse that, try this regex pattern: \/Date\((\d+)\+(\d+)\)\/ I'm not a java guy but regex is everywhere. I looks like the date is in miliseconds so you need to divide 1521866513877 / 1000 to get the

How to change date format of datetime data type in SQL?

落爺英雄遲暮 提交于 2020-01-17 03:54:24
问题 My date format of "03-01-2017 10:24:48" is getting stored in SQL as "2017-03-01 10:24:48.000" where my 'dd-mm-yyyy' format is getting converted to 'yyyy-mm-dd' format. How can I change the date format of the column to my desired format? My table already contains data. 回答1: SQL Server doesn't store a DateTime in any string format - it's stored as an 8 byte numerical (binary) value. The various settings (language, date format) only influence how the DateTime is shown to you in SQL Server

How to set format of current date time to different format?

孤街醉人 提交于 2020-01-13 07:13:26
问题 I use the following code to retrieve the current date and time, then add it to table using following method. Change 2013-07-29 23:20:34.0 to 29th July 2013, 11:20 PM DateTime public Date getCurrentDateTime() { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); System.out.println("current:" + dateFormat.format(date)); return date; } Hibernate @Temporal(javax.persistence.TemporalType.TIMESTAMP) public Date getCurrentDateTime() { return date; } 回答1

Convert SimpleDateFormat to DateTimeFormatter

旧城冷巷雨未停 提交于 2020-01-12 13:52:06
问题 So when trying to replace some legacy code using SimpleDateFormat and Date, to use java.time.DateTimeFormatter and LocalDate I ran into a problem. The two date formats are not equivalent. At this point I must say I know the two date types are not the same but the scenario I am in means I never care about the time aspect so can ignore it. public Date getDate(String value) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); try { return dateFormat.parse(value); } catch

Convert SimpleDateFormat to DateTimeFormatter

守給你的承諾、 提交于 2020-01-12 13:51:19
问题 So when trying to replace some legacy code using SimpleDateFormat and Date, to use java.time.DateTimeFormatter and LocalDate I ran into a problem. The two date formats are not equivalent. At this point I must say I know the two date types are not the same but the scenario I am in means I never care about the time aspect so can ignore it. public Date getDate(String value) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); try { return dateFormat.parse(value); } catch

Where are the Java 8 DateTimeFormatters constants defined?

拜拜、爱过 提交于 2020-01-12 08:56:14
问题 I am looking at the DateTimeFormatter class and I was wondering where are the constants like "M" , "EEE" and "YY" etc are defined. More specifically there should be code like this somewhere given a ChronoField and TextStyle, it should return the DateTimeFormatter string snippet e.g. (ChronoField.MONTH_OF_YEAR, TextStyle.SHORT) should map to the string "MMM" 回答1: After some source digging, I found out that these are pre-defined in a private static final Map , called FIELD_MAP , which is a

Where are the Java 8 DateTimeFormatters constants defined?

我与影子孤独终老i 提交于 2020-01-12 08:56:03
问题 I am looking at the DateTimeFormatter class and I was wondering where are the constants like "M" , "EEE" and "YY" etc are defined. More specifically there should be code like this somewhere given a ChronoField and TextStyle, it should return the DateTimeFormatter string snippet e.g. (ChronoField.MONTH_OF_YEAR, TextStyle.SHORT) should map to the string "MMM" 回答1: After some source digging, I found out that these are pre-defined in a private static final Map , called FIELD_MAP , which is a