date-conversion

Error converting date with two digits for the Year field

岁酱吖の 提交于 2021-02-08 06:55:31
问题 // input format: dd/MM/yy SimpleDateFormat parser = new SimpleDateFormat("dd/MM/yy"); // output format: yyyy-MM-dd SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); System.out.println(formatter.format(parser.parse("12/1/20"))); // 0020-11-01 I am using the above code but it is giving me year as '0020' instead of '2020'. 回答1: Use java.time for this: public static void main(String[] args) { String dateString = "12/1/20"; LocalDate localDate = LocalDate.parse(dateString,

Convert column with Month Name and Year to integer with format YYYYMM in MySQL

守給你的承諾、 提交于 2021-01-29 02:35:42
问题 I have a date column like the next one stored as VARCHAR (not DATE type) and I want to convert it to an INTEGER type with next format: YYYYMM . So, for example, if this where my sample data: period "January 2018" "February 2018" "March 2018" I would like to get the next integers: result 201801 201802 201803 I have tried the next code: select period, str_to_date(period, '%M %Y') as yearperiod from table But this gives, for example, 2018-01-00 format which I would like to convert to the integer

Python timezone conversion adding minutes to the hour?

隐身守侯 提交于 2020-07-16 06:40:07
问题 So I'm trying to convert a bunch of hours (10:00:00, 14:00:00, etc) from a given timezone to UTC. When I do so, I keep maddeningly getting things back like "15:51:00". When you get to that line, and print what value it's using, it's using something like: 1900-01-01 12:00:00-05:51 Which is fine, except for the -05:51 bit. I have no idea why that -05:51 is there, and it's causing me problems. UTC conversion is hour to hour, yes? I think it's got something to do with my timezone conversions, but

Python timezone conversion adding minutes to the hour?

折月煮酒 提交于 2020-07-16 06:38:54
问题 So I'm trying to convert a bunch of hours (10:00:00, 14:00:00, etc) from a given timezone to UTC. When I do so, I keep maddeningly getting things back like "15:51:00". When you get to that line, and print what value it's using, it's using something like: 1900-01-01 12:00:00-05:51 Which is fine, except for the -05:51 bit. I have no idea why that -05:51 is there, and it's causing me problems. UTC conversion is hour to hour, yes? I think it's got something to do with my timezone conversions, but

Python timezone conversion adding minutes to the hour?

懵懂的女人 提交于 2020-07-16 06:38:33
问题 So I'm trying to convert a bunch of hours (10:00:00, 14:00:00, etc) from a given timezone to UTC. When I do so, I keep maddeningly getting things back like "15:51:00". When you get to that line, and print what value it's using, it's using something like: 1900-01-01 12:00:00-05:51 Which is fine, except for the -05:51 bit. I have no idea why that -05:51 is there, and it's causing me problems. UTC conversion is hour to hour, yes? I think it's got something to do with my timezone conversions, but

How to get start time and end time of a day in another timezone in Android

若如初见. 提交于 2020-06-25 07:08:52
问题 I've the date in format: YYYY-MM-DD Output format required is: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" And I want to get the date in ISO format as Start time of the day(starts from 12:00AM) and end time of the day(ends on 11:59PM) in America/Chicago timezone. For eg. For the date: 2020-06-08 (June 8) the converted final output is like: Start time of the day as Date: 2020-06-08T05:00:00.000Z End time of the day as Date: 2020-06-09T04:59:59.999Z Please help me here if anybody has any clue for the same.

Convert Date String to another Date string with different format

一曲冷凌霜 提交于 2020-06-23 07:06:06
问题 I need to convert an string date with format yyyyMMdd to a date string with format MM/dd/yyyy . Which is the best to do it? I'm doing this: DateTime.ParseExact(dateString, "yyyyMMdd", CultureInfo.InvariantCulture).ToString("MM/dd/yyyy") But I'm not sure, i think there must be a better way. What do you think? 回答1: What you are doing is fine. Probably you can improve it by using DateTime.TryParseExact and on successful parsing, format the DateTime object in other format. string dateString =

VBA - convert to date

孤街浪徒 提交于 2020-05-14 14:57:07
问题 I have one more time a problem: I want to convert from Strings to dates in VBA The Strings look like: YYYY-DD-MM The date should be like: DD.MM.YYYY I know, normally you do this with the method cdate(), but it doesn't work here. I think it's because the structure of the string is bad to convert. thanks for your help InformatikBabo 回答1: Sub Main() Dim strDate As String strDate = "2013-06-11" Debug.Print "Original Date: ", strDate Debug.Print "CDate() Conversion: ", CDate(strDate) Debug.Print

Good way to convert integer YYYYMMDD into java.util.Date with local time zone

老子叫甜甜 提交于 2020-01-30 13:09:25
问题 I understand this question could look like FAQ subject but critical things here is time zone and performance. I have integer YYYYMMDD date (20150131 is example). Here is good 'almost working' solution: import org.joda.time.DateTime; import java.util.Date; // ... public Date extract(final int intDate) { Date result = null; try { result = new DateTime( intDate / 10000, (intDate / 100) % 100, intDate % 100, 0, 0, 0, 0).toDate(); } catch (final IllegalArgumentException e) { // Log failure }

Good way to convert integer YYYYMMDD into java.util.Date with local time zone

依然范特西╮ 提交于 2020-01-30 13:09:13
问题 I understand this question could look like FAQ subject but critical things here is time zone and performance. I have integer YYYYMMDD date (20150131 is example). Here is good 'almost working' solution: import org.joda.time.DateTime; import java.util.Date; // ... public Date extract(final int intDate) { Date result = null; try { result = new DateTime( intDate / 10000, (intDate / 100) % 100, intDate % 100, 0, 0, 0, 0).toDate(); } catch (final IllegalArgumentException e) { // Log failure }