simpledateformat

BlueMix service error with Android app - 'Unknown pattern character 'X''

跟風遠走 提交于 2019-12-11 13:37:25
问题 I'm developing an android application and am attempting to integrate the Bluemix service - Personality Insights. However, due to a conflict with dates (Bluemix service is assuming a Java SimpleDateFormat which includes the symbol 'X', while Android's SimpleDateFormat does not include this symbol) causing an error (Log below). My question is this, is there a way to brute force the app to use the Java SimpleDateFormat version as opposed the Android version? other than that I don't see how I can

SimpleDateFormat getHours() return incorrect value

半腔热情 提交于 2019-12-11 11:42:11
问题 Why getHours() for "09:50" return 8? Code: SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); Date date = sdf.parse("09:50"); int hours = date.getHours(); // return 8 instead of 9 ??? 回答1: Calendar prueba = Calendar.getInstance(); prueba.set(2013, 1, 6, 10, 49, 32); int day = prueba.get(Calendar.DAY_OF_MONTH); int month = prueba.get(Calendar.MONTH); int year = prueba.get(Calendar.YEAR); int hours = prueba.get(Calendar.HOUR); int minutes = prueba.get(Calendar.MINUTE); int seconds = prueba

SimpleDateFormat returns wrong date value during parse

允我心安 提交于 2019-12-11 11:33:21
问题 I m facing a problem:I want to get current time of GMT TimeZone in long. I m using the following code as given below: TimeZone timeZoneGmt = TimeZone.getTimeZone("GMT"); long gmtCurrentTime = getCurrentTimeInSpecificTimeZone(timeZoneGmt); public static long getCurrentTimeInSpecificTimeZone(TimeZone timeZone) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(timeZone); long finalValue = 0; SimpleDateFormat sdf = new SimpleDateFormat( "MMM dd yyyy hh:mm:ss:SSSaaa"); sdf.setTimeZone

SimpleDateFormat gives java.lang.classcastexception: java.util.date

三世轮回 提交于 2019-12-11 11:32:13
问题 String str = "13/06/2011"; SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); Date date = (Date)formatter.parse(str); 回答1: I guess that your Date class is actually a java.sql.Date . 回答2: What does your import statement say? Are you importing some other class (for example java.sql.Date ) by accident? What does the compiler say when you remove the class cast (which should not be there)? 回答3: DateFormat.parse() returns an instance of java.util.Date and not java.sql.Date . In order

Parsing timezone from a string with offset using SimpleDateFormat

折月煮酒 提交于 2019-12-11 11:25:46
问题 Decided to ask this, as I couldn't find a similar example in StackOverflow. I want to parse a date string and its timezone using SimpleDateFormat. I (hope) I read the documentation carefully, and wrote this program that replicates the issue. import java.text.DateFormat; import java.util.Date; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Locale; public class SDF { private static final String FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; public static void main

Android “Loaded time zone names for en in __ms.”

倾然丶 夕夏残阳落幕 提交于 2019-12-11 11:19:34
问题 The app I'm writing loads an RSS feed using the HorrorRSS library. The problem I'm facing is that looking at the logs I see oodles of this junk: 10-06 12:58:36.939: I/global(3159): Loaded time zone names for en in 624ms. 10-06 12:58:37.329: I/global(3159): Loaded time zone names for en in 368ms. 10-06 12:58:37.709: I/global(3159): Loaded time zone names for en in 370ms. 10-06 12:58:38.149: I/global(3159): Loaded time zone names for en in 403ms. 10-06 12:58:38.589: I/global(3159): Loaded time

Java SimpleDateFormat similar to C#

天大地大妈咪最大 提交于 2019-12-11 10:43:53
问题 I have to get a today Date with this format {"Date":"2013-09-11T14:47:57.8895887+02:00"} . This is because my Json Service is studied for Windows Phone and C# code. I tried with this method: public static Date getTodayDate() { SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSZ:Z"); Date date = new Date(); String dateString = dateFormat.format(date); Date today = parseFromNormalStringToDate(dateString); return today; } but I get this return 2013-09-16T11:47:55.235

Change date format Nov 18, 2014 to 2014-11-18

*爱你&永不变心* 提交于 2019-12-11 09:38:40
问题 I am trying to change the format of a date but cannot get it to work from Nov 18, 2014 to 2014-11-18 String s="Nov 18, 2014" s= new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("LLL dd, yyyy").parse(s)); something is wrong with this part new SimpleDateFormat("LLL dd, yyyy").parse(s) 回答1: Change LLL to MMM and it should work. LLL is not defined (corrent value). You should look at Class SimpleDateFormat at official docs Common Pattern Strings for java.text.SimpleDateFormat As

Java: where is source of unwanted behavior in my JFormattedTextField?

南笙酒味 提交于 2019-12-11 09:17:59
问题 My current Java project requires me to work with dates and through my research and tinkering around I discovered the setLenient() method is defaulted to true . When I set it to false I begin to have problems with my code. I have a JFormattedTextField intialized with a SimpleDateFormat . For my project, I need to have / placeholders always present so using the answer to this question, I was able to install / s as place holders in the form of MM/dd/yyyy When the SimpleDateFormat is set to

Why SimpleDateFormat.format() and SimpleDateFormat.parse() are giving different time though setting only one TimeZone?

守給你的承諾、 提交于 2019-12-11 09:15:19
问题 I am trying to set the Timezone to the different country's timezone with help of SimpleDateFormat . SimpleDateFormat.format() returns correct current time of the given Timezone, but SimpleDateFormat.parse() returns local current time, I dont know why this is happening. Here is the my code - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss"); dateFormat.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles")); System.out.println("Time1 : " + dateFormat.format(new Date())