date-format

Parsing Java dates with truncated timezone information

余生颓废 提交于 2019-12-10 19:20:45
问题 Consider the following date string 2012-10-01 01:02:03.004+0500 This is recognized in Java using the following SimpleDateFormat pattern: yyyy-MM-dd HH:mm:ss.SSSZ If, however, the timezone information above is truncated to 2 digits, i.e. like 2012-10-01 01:02:03.004+05 the date string does not comply to any valid format, so there is no SimpleDateFormat pattern that could be used in order to correctly parse it. Is there any workaround for parsing the truncated timezone correctly without string

Format Date Java

ε祈祈猫儿з 提交于 2019-12-10 18:40:05
问题 How to format a string that looks like this Sat Dec 08 00:00:00 JST 2012 into yyyy-mm-dd i.e. 2012-12-08 From browsing the web, I found this piece of code: SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy"); String dateInString = "Sat Dec 08 00:00:00 JST 2012"; try { Date date = formatter.parse(dateInString); System.out.println(date); System.out.println(formatter.format(date)); } catch (ParseException e) { e.printStackTrace(); } However, I am unable to modify it to accept the

Rails to_json uses different DATE_FORMATS that .to_s

末鹿安然 提交于 2019-12-10 17:41:17
问题 With the following in my rails_defaults.rb: Date::DATE_FORMATS[:default] = '%m/%d/%Y' Time::DATE_FORMATS[:default]= '%m/%d/%Y %H:%M:%S' Why do the following results differ: ruby-1.9.2-p180 :005 > MyModel.find(2).to_json(:only => :start_date) => "{\"start_date\":\"2012-02-03\"}" ruby-1.9.2-p180 :006 > MyModel.find(2).start_date.to_s => "02/03/2012" And more importantly, how do I get to_json to use %m/%d/%Y ? 回答1: Because the standard JSON format for a date is %Y-%m-%d and there's no way to

Inconsistent `w` symbol formatting from joda time to java.time

梦想的初衷 提交于 2019-12-10 17:29:02
问题 My team is looking to switch from Joda time to java.time , but we're seeing different behavior in formatting using the same pattern. The issue arises when we're using the week-of-week-year w symbol: final String dateString = "2016-01-04 00:00:00"; final String inputPattern = "yyyy-MM-dd HH:mm:ss"; // parse the input string using Joda final org.joda.time.format.DateTimeFormatter jodaInputFormatter = org.joda.time.format.DateTimeFormat.forPattern(inputPattern); final org.joda.time.DateTime

convert date from “2009-12 Dec” format to “31-DEC-2009”

﹥>﹥吖頭↗ 提交于 2019-12-10 16:46:19
问题 '2009-12 Dec' should be converted to '31-DEC-2009' '2010-09 Sep' should be converted to '30-SEP-2010' '2010-02 Feb' should be converted to '28-FEB-2010' '2008-02 Feb' should be converted to '29-FEB-2008' The values 2009-12 Dec , 2008-02 Feb will be displayed to the User in a drop down. The User have no option to select the DAY . The user selected value should be passed to the Database. But the database expects the date in the format DD-MMM-YYYY . The query has ' <= USER_DATE ' condition. So,

Date format problem using SSIS for Excel into SQL Server

天涯浪子 提交于 2019-12-10 16:39:57
问题 I am trying to import a column of dates from a spreadsheet in Excel 2003 into SQL Server 2005 using SSIS. I am in the UK so want dates formatted as dd/MM/yyyy. Unfortunately, the column in the spreadsheet contains a mixture of dates stored as strings in dd/MM/yyyy (with Excel 'General' formatting) as well as dates using Excel 'Date' formatting dd/MM/yyyy (with locale 'English (United Kingdom)'). This is just the way it is and I can't expect the users to be able to sort this out themselves.

How to remove the SECONDS field from a DateFormat

南楼画角 提交于 2019-12-10 15:58:33
问题 I want to print a time without seconds in the default format for the locale. So I get the formatter with getTimeInstance() or getTimeInstance(int style) . But even when I use a SHORT style it will contain the seconds part of the time as well. Is there any way (apart from creating my own format, which then would not be the locale default and manually maintained) I can grab the default and split off the seconds ? Thanks Roman 回答1: DateFormat.getTimeInstance( DateFormat.SHORT ) works perfectly

Android How to change Total number of days into years,months and days exactly?

♀尐吖头ヾ 提交于 2019-12-10 14:45:20
问题 i am doing an app that is related to get the age of a person according to the given input of birthday date. for that i am getting the total number of days from that date to the current date from the below code. String strThatDay = "1991/05/10"; SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); Date d = null; try { try { d = formatter.parse(strThatDay); Log.i(TAG, "" +d); } catch (java.text.ParseException e) { e.printStackTrace(); } } catch (ParseException e) { e.printStackTrace

SWT DateTime format change

旧城冷巷雨未停 提交于 2019-12-10 14:04:09
问题 I'm using a DateTime SWT component, and it has an American format when displayed (mm/dd/yyyy). Is there any way to change the format to dd/mm/yyyy ? 回答1: DateTime uses the OS specific user preferences to format the date. (On Windows these are the Regional and Language Options in the system settings). A possible workaround is described here (scroll down to the latest two entries). But I haven't tried this myself. 回答2: You need to set the locale to change the date format, e.g. to Italy who use

Custom date format in android for given locale

隐身守侯 提交于 2019-12-10 11:02:14
问题 I'm trying to format a date for a given locale new Locale("mk", "MK") . The locale is valid, it returns the country name and language properly. I want to use custom string, in my case "E, kk:mm" or "EEEE, kk:mm". I want the output to be "сабота, 12:00", but what I get is "7, 12:00". This is how I use it and I tried many ways, but they all seem to behave the same. SimpleDateFormat sdf = new SimpleDateFormat("EEEE, kk:mm", new Locale("mk", "MK)); sdf.format(new Date()); // output: 7, 12:30