simpledateformat

SimpleDateFormat android not formatting as expected

风格不统一 提交于 2019-12-11 08:53:33
问题 I'm trying to use SimpleDateFormat for formatting a date represented by 3 ints. It looks like this: ... SimpleDateFormat sdfHour = new SimpleDateFormat("HH"); SimpleDateFormat sdfMinute = new SimpleDateFormat("mm"); SimpleDateFormat sdfSecond = new SimpleDateFormat("ss"); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getDefault()); int hours = c.get(Calendar.HOUR_OF_DAY); int minutes = c.get(Calendar.MINUTE); int seconds = c.get(Calendar.SECOND); String string_hours = sdfHour

Formatting ISO 8601 in Java 7

怎甘沉沦 提交于 2019-12-11 07:28:23
问题 I have date format like this 2016-11-25T09:29:10.588+01:00 I want to convert this to milliseconds and later while printing I have to again convert milliseconds to " yyyy-MM-dd HH:mm:ss.SSS " this format. static FastDateFormat alarmDateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSS"); DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSXXX"); df1.setTimeZone(TimeZone.getTimeZone("UTC")); String string1 = "2016-11-25T09:29:10.588+01:00"; Date result1 = df1.parse

Parse specific date string format

一笑奈何 提交于 2019-12-11 07:04:59
问题 I have read a lot of questions and searched for a lot of libs all over the internet but I can't find one that can do this quickly. I want to parse a specific date in a specific date format like this: String date = "20130516T090000"; SimpleDateFormat x = new SimpleDateFormat("yyyyMMddTHHmmss"); String theMonth = x.parse(date, "M"); // 05 String theMonth = x.parse(date, "MMM"); // MAY String theMinute = x.parse(date, "mm"); // 00 String theYear = x.parse(date, "yyyy"); // 2013 Just simple as

Inconsistency in java date library for week of year

走远了吗. 提交于 2019-12-11 04:24:52
问题 As per https://en.wikipedia.org/wiki/ISO_8601#Week_dates, Weekdays start on Monday. But, from Java, if you try to extract week number in two different ways, two different outputs come if the date is a Sunday. import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; public class TestDate { public static void main(String[] args) throws ParseException { final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); final SimpleDateFormat

SimpleDateFormat not showing the right date format

狂风中的少年 提交于 2019-12-11 04:18:44
问题 I have a DateTime field in my SQL database holding and when I try to show it in my JSP page and format it using "dd-MM-yyyy hh:mm:ss", it displays correctly only the date part. For example, for the date "2012-01-19 12:13:48" stored in the database it shows "19-01-2012 12:00:00". What may be the problem? Code: SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"); sdf.format(rs.getDate("comment_date")); //rs -> ResultSet 回答1: From the javadoc for java.sql.Date : To conform with

Parse Error in Java Program

Deadly 提交于 2019-12-11 04:14:42
问题 the error occur near the parsing of proj_close_date.( java.text.ParseException: Unparseable date: "09/09/2010" ) i am reading project_close_date value from database which is in string format. i want convert it in to date format to find that, is proj_close_date present between from_date and to_date public ArrayList viewAllCustProj1(String frm_date,String to_date,String cust,String proj) { ArrayList list= new ArrayList(); try { String strCust=""; String strproj=""; if(!cust.equalsIgnoreCase(

SimpleDateFormat Unparseable date Error if locale is ES. Twitter “Created_At”

好久不见. 提交于 2019-12-11 03:45:12
问题 I'm trying to convert the twitter "created_at" to an Argentinian Date-time. If I do this: final String TWITTER="EEE MMM dd HH:mm:ss"; SimpleDateFormat sf = new SimpleDateFormat(TWITTER,new Locale("en")); It works fine. But if I change to Locale("es") , Locale("es","ES") or Locale("es","AR") , I am getting this error: 07-01 11:09:29.153: W/System.err(331): java.text.ParseException: Unparseable date: "Tue Jul 01 13:57:36 +0000 2014" Why can't I convert the date to my local time? EDIT: Based on

ThreadLocal for multithreaded access to SimpleDateFormat

痴心易碎 提交于 2019-12-11 03:33:45
问题 I have a number of Java date patterns and want to reuse them multiple times in SimpleDateFormat objects across different threads, via static references, for speed. The code would look something like this (inside a class called, say, FormatClass ): private static String[] PATTERNS = new String[] {...}; public ThreadLocal<SimpleDateFormat[]> LOCAL_FORMATS = new ThreadLocal<SimpleDateFormat[]> { @Override protected SimpleDateFormat[] initialValue() { List<SimpleDateFormat> formatList = new

SimpleDateFormat incorrectly parsing string

拟墨画扇 提交于 2019-12-11 03:32:32
问题 String s = 19.17.38.008000; DateFormat f = new SimpleDateFormat("HH.mm.ss.SSSSSS"); Date d = f.parse(s); system.out.println(d); this is the code I am running it runs fine except when it prints it prints the time 19:17:46. Please someone explain this to me As a side note: String s = 19.17.38.008000; DateFormat f = new SimpleDateFormat("HH.mm.ss"); Date d = f.parse(s); system.out.println(d); this code will print the same string correctly minus the milliseconds. Someone please tell me what I am

ParseException - Can't figure out the right pattern

会有一股神秘感。 提交于 2019-12-11 03:18:46
问题 I have the following string: dateToParse = "Fri May 16 23:59:59 BRT 2014" , and want to parse it using DateFormat: DateFormat dateFormat = new SimpleDateFormat(pattern, Locale.getDefault()); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("America/Sao_Paulo")); cal.setTime(dateFormat.parse(dateToParse)); right now I'm trying it with pattern = "EEE MMM dd HH:mm:ss z yyyy" , but get this exception: java.text.ParseException: Unparseable date: "Fri May 16 23:59:59 BRT 2014" (at offset 0)