date-conversion

How to convert date as string from 17-Dec-2018 to 2018-12-17 in java. I want to store it to MYSQL database

谁都会走 提交于 2019-12-24 20:32:39
问题 I have successfully imported date column from excel to the java code. However, I am unable to change the date format from 17-Dec-2018 to 2018-12-17. Kindly help. public void saveToDatabase(Vector dataHolder) throws ParseException { System.out.println(dataHolder); for(Iterator iterator = dataHolder.iterator();iterator.hasNext();) { List list = (List) iterator.next(); fullName = list.get(0).toString(); idNumberString = list.get(1).toString(); //idNumber = Integer.parseInt ( idNumberString );

Converting string to java.util.date

有些话、适合烂在心里 提交于 2019-12-24 15:35:39
问题 I am working with date strings that need to be converted to java.util.date objects. I'm using the following code to do this: public void setDates(String from, String to) throws ParseException { Date fromDate = new Date(); Date toDate = new Date(); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); fromDate = df.parse(from); toDate = df.parse(to); this.setDepartDate(fromDate); this.setReturnDate(toDate); } The problem is that the string values that I have to convert are always(And I

MySQL convert month number to month name

这一生的挚爱 提交于 2019-12-24 11:23:00
问题 Is it possible to convert an integer/column to month name in MySQL? For example, 1 becomes 'Jan' or 'January'. 13 and onwards give an error, or will be never used. 回答1: We can convert the given input number to MySQL date format (focusing on month only), using Str_To_Date() function. Now, we simply need to use Monthname() function to extract the month name from the date. This will work only when NO_ZERO_DATE mode is disabled. Try: SET sql_mode = ''; -- disable NO_ZERO_DATE mode SELECT

String to Date conversion (everything seems good but fail)

元气小坏坏 提交于 2019-12-24 10:25:03
问题 How to parse this string? "Mon Jul 02 13:49:16 CEST 2012" String Date = "Mon Jul 02 13:11:38 CEST 2012"; DateFormat formatter; Date convertedDate= new Date(); formatter = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy"); try { convertedDate = (Date) formatter.parse(Date); } catch (ParseException ex) { Logger.getLogger(ItemRecTestCases.class.getName()).log(Level.SEVERE, null, ex); } Dont work..." java.text.ParseException: Unparseable date: " 回答1: You need to set the locale : formatter = new

How to only keep the time portion of a datetime value (SQL Server)?

拈花ヽ惹草 提交于 2019-12-24 01:15:57
问题 Here's what I use to get a HH:MM string: CONVERT(varchar(5), time_requested, 108) I'm thinking there may be a more elegant way, even maybe more efficient (see similar question on How to remove the time portion of a datetime value (SQL Server)?). Requirements: the final result has to be easily convertible to a string (in order to be able to concatenate some field time_created with a field such as date_created ). the following 2 cases must be covered: HH:MM and HH:MM:SS . 回答1: Declare @D

How to split minutes into days, hours and minutes in tsql

蓝咒 提交于 2019-12-22 11:09:19
问题 I have a column which consist of minutes. Is there any simple way to split minutes column into one column which shows days, hours, minutes only? DURATION ----------- 67 ==> 1 hour, 7 minutes 1507 ==> 1 day, 1 hour, 7 minutes 23 ==> 23 minutes I googled for solution but I didn't find any solution similar for me. I want to show this in a report but trying to find how can I solve this column looks meaningfully. Duration column's calculation like this. avg(datediff(MINUTE, ei.SentDate, eo

Convert XMLGregorianCalendar in GMT to LocalDateTime Pacific time

会有一股神秘感。 提交于 2019-12-22 09:32:13
问题 I'm trying to convert XMLGregorianCalendar which is sent in GMT/UTC format to Java 8 LocalDateTime in America/Los_Angeles timezone with no luck. Here is what I tried and couldn't get the time converted to Pacific time. //xmlDate is 2017-11-13T00:00:00Z ZonedDateTime zDateTime = xmlDate.toGregorianCalendar().toZonedDateTime().toLocalDateTime().atZone(ZoneId.of("America/Los_Angeles")); LocalDateTime localDateTime = zDateTime.toLocalDateTime(); //Expected localDateTime is 2017-11-12T16:00. But I

In SQL Server, how to convert a date to a string in format M/D/YYYY? (no leading zeros, not MM/DD/YYYY)

白昼怎懂夜的黑 提交于 2019-12-21 07:55:42
问题 Right now, my code has the following conversion for a date field: convert(varchar, Citation.PublishedOn, 101) However, that returns dates like 03/01/2010. The request was to have the dates display as 3/1/2010 (without the leading zeros, but with a 4 digit year). I've looked at http://msdn.microsoft.com/en-us/library/ms187928.aspx and I'm not seeing anything that explicitly excludes leading zeros. How do I format the date to exclude leading zeros? 回答1: This is how I would do it: DECLARE @dt

sql server Get the FULL month name from a date

只谈情不闲聊 提交于 2019-12-18 18:57:26
问题 How do I use sql to get the whole month name in sql server? I did't find a way using DATEPART(mm, mydate) or CONVERT(VARCHAR(12), CreatedFor, 107) . Basically I need in the format: April 1 2009 . 回答1: SELECT DATENAME(MONTH, GETDATE()) + RIGHT(CONVERT(VARCHAR(12), GETDATE(), 107), 9) AS [Month DD, YYYY] OR Date without Comma Between date and year, you can use the following SELECT DATENAME(MONTH, GETDATE()) + ' ' + CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + CAST(YEAR(GETDATE()) AS VARCHAR(4))

What does bb or bbbb represent in an EN-US TEXT function or Custom Number format mask?

倖福魔咒の 提交于 2019-12-18 09:26:22
问题 On a EN-US regional system, what does B or b represent in a format mask? While it does nothing in VBA's Format function, both the TEXT function and Custom Number Formatting recognize b as a legal Number Format Code and return a number that I cannot determine the origin of. To further confuse matters, larger numbers return different values when formatted with bbbb and while blocks of sequential numbers return the same value, there are transitions when they jump ahead a digit. I do know that