Intermitted SimpleDateFormat problems
Alright, encountered a very strange problem when using SimpleDateFormat to parse a date string. Primarily, I have 2 applications that exchange data over 2 remote sites using flat-files. They have a timestamp as a header along with some other information. The jobs have not been touched, and the code remains exactly the same. However, SimpleDateFormat.parse() throws a variety of exceptions intermittently but they seem to work most of the time. For simplicity, I have only included the code pertaining to the Date Format being used.
SimpleDateFormat TIMESTAMP = new SimpleDateFormat("yyyyMMddHHmmss");
TIMESTAMP.setLenient(false);
TIMESTAMP.parse(someArbritaryTimestamp);I have already checked the actual flat files, and have found that the timestamp format is indeed valid. For example, today morning the timestamp was 20040229065504 and I got a parse exception.
I have even had crashes such as the following stack trace when the date was formatted correctly.
For input string: ".551E"
- java.lang.NumberFormatException.forInputString(Unknown Source)
- java.lang.FloatingDecimal.readJavaFormatString(Unknown Source)
- java.lang.Double.parseDouble(Unknown Source)
- java.text.DigitList.getDouble(Unknown Source)
- java.text.DecimalFormat.parse(Unknown Source)
- java.text.SimpleDateFormat.subParse(Unknown Source)
- java.text.SimpleDateFormat.parse(Unknown Source)
- java.text.DateFormat.parse(Unknown Source)
Another crash was
For input string: ""
- java.lang.NumberFormatException.forInputString(Unknown Source)
- java.lang.Long.parseLong(Unknown Source)
- java.lang.Long.parseLong(Unknown Source)
- java.text.DigitList.getLong(Unknown Source)
- java.text.DecimalFormat.parse(Unknown Source)
- java.text.SimpleDateFormat.subParse(Unknown Source)
- java.text.SimpleDateFormat.parse(Unknown Source)
- java.text.DateFormat.parse(Unknown Source)
And the most interesting one
multiple points
- java.lang.FloatingDecimal.readJavaFormatString(Unknown Source)
- java.lang.Double.parseDouble(Unknown Source)
- java.text.DigitList.getDouble(Unknown Source)
- java.text.DecimalFormat.parse(Unknown Source)
- java.text.SimpleDateFormat.subParse(Unknown Source)
- java.text.SimpleDateFormat.parse(Unknown Source)
- java.text.DateFormat.parse(Unknown Source)
Searched the forums, couldn't find anything that was remotely similar. Couldn't find a bug in Java as well. Any ideas? If not, the only alternative I can see is that the JVM installed on the machine could possible be corrupted
Hi,
I recently encountered this issue in my code, and it really through me for a loop since the code hadn't changed in years. I found this forum posting first (many thanks) which pointed me towards the fact that the problem is around thread safety with the SimpleDateFormat class. I still thought it was a bit odd since my code always calls SimpleDateFormat .parse() from the same thread, and the SimpleDateFormat object is private to my class.
Following up some more I found this Bug ID (4228335) in the Java Bug Parade. It is marked as closed, since it was fixed via another bug, but as far as I can tell the fix was simply to update the API docs to indicate that SimpleDateFormat is not thread safe. However, this bug ID seems to indicate that the thread-safety issue isn't external to users of SimpleDateFormat , but internal to the code path once parse() or format() are called. There are quite a few angry rants posted against this bug, as well as suggestions on how to address it - a few of those suggestions involve modification to the JDK source code.
I found that my application exhibited these specific characteristics:
- the SimpleDateFormat is used extenisvely to format a date string coming back over a Socket connection. Occasionally, the call to SimpleDateFormat .parse() threw a NumberFormatException, but it never occurrred consistently. There did seem to be a corelation between the occurences of this exception, and the processor speed of the PC running the application. On a 3.0 gigahertz machine, it was seen more often.
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.text.DigitList.getLong(Unknown Source)
at java.text.DecimalFormat.parse(Unknown Source)
at java.text.SimpleDateFormat.subParse(Unknown Source)
at java.text.SimpleDateFormat.parse(Unknown Source)
Workaround
Basically I subclassed SimpleDateFormat, overrode the parse() and format() methods and synchronized them. In the parse() method, I catch a NumberFormatException, and try the parse() again. If it fails a second time I simply create a new Date and return it. Fortunately the Date variable is not critical for my application.
This is certainly not a foolproof solution, and I think synchronizing the parse() and fomat() methods are adjusting the timing enough to reduce the occurences of the exception being thrown. Again, in my code the parse() call is only ever made from a single thread.
Anyway, I just wanted to share my experience, since I know first-hand how frustrating this bug can be.
Similar Messages
-
Hi
I ran into a strange error today with SimpleDateFormat .
In the following code:
SimpleDateFormat format =
new SimpleDateFormat("yyyyMMddHHmmss");
format.setLenient(false);
try
Date date = format.parse("19850414000000");
catch (ParseException e)
e.printStackTrace();
}I receive an exception:
java.text.ParseException: Unparseable date: "19850414000001"
at java.text.DateFormat.parse(Unknown Source)
at test.MainClass.main(MainClass.java:101)
Could someone please tell me whats wrong with the date: 19850414000001 ?
Actually after checking some more, all the times between 19850414000000 and 19850414005959 give this error while for example 19850414010000 or 19850413235959 work fine.
Also this only happens for setLenient(false).
What happened on the 14th of april 1985 that the Parser doesn't want to talk about?
Thanks
AharonFunny. This occurs with certain timezones only:
package test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
public class Test {
public static void main(String... args) {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
format.setLenient(false);
for (String timeZoneId : TimeZone.getAvailableIDs()) {
format.setTimeZone(TimeZone.getTimeZone(timeZoneId));
try {
format.parse("19850414000000");
} catch (ParseException e) {
System.out.println("Failed on timezone " + timeZoneId);
Failed on timezone Asia/Gaza
Failed on timezone Asia/Jerusalem
Failed on timezone Asia/Tel_Aviv
Failed on timezone IsraelThere's a pattern .. Something Jewish? -
Email problems and the incompetence of BT call cen...
How come one can come on this forum and read threda after thread of people complaining about intermitant email problems yet when you ring the call centre you are fobed off with the usual excsue that it is your settings that are the problem.
For me, it was only after wasting 30 minutes of my time, in which the memebr of the 'technical' team tried to look at my settings, this involved him entering the wrong information on several occasions and needing to be corrected by myself. That the person admitted that there had been a problem.
What is interetsing is that I explained that i receive emails through my Ipad and sometimes collect by BT Yahoo, as well as my PC, none of which were working and all of which require the setting to lon on to the serever to be set individually, I also made it quite clear that was an intermitant problem, but that today it had lasted 8 hours. Yet still we went this through redicilous rigmorole of playing with the settings on my PC - why?
The gentlemen then admitted there was a problem with BT yahoo, so very unimpressed I asked to speak to the complaints department. I was put through to a 'manager' and I use that term guardedly because he was no more competent then the first person I spoke to. He said that perhaps his colleugue had failed to check the system status recently, I suggest that he had not chceked it for at least 8 hours as that is how long my emial has been down today! This man then began the fob of speech, refusing to put me through to someone who would help and saying he had all the authority to help me, afetr several questions it became clear he had no authroity whatsoever, he could not talk about bills, he could even get me the details of the complaints department in Durham, apparently it deos not exist!
Anyway I am sharing my story to see if anyone thinks that the call centre that BT farm their work out to are entirely incompetent and are seriously in need of some training, the first thing they need to do is actually listen to the customer and not begin the decision tree they think roughly addresses the problem.
'ah email'
step 1 - click 'email connection problem'
step 2 - check settings
It just might be that some of us do actually know what we are talking about, and have had experience setting up call centers so we know hoe they work.
Please, please allow us to speak to people who will help us with our problem it is the only way you will retain customers in a competive telecommunications sector.
Just stop fobbing us off with the line, 'it must be your settings' but admit you have a problem and get it fixed!!
Ironically as I type 'fixed' yet another 0x800ccc92 falshes up on screen, showing that my issues still remain unresolved.Hi Cross_Bug.
First of all i too know how frustrating it can be being put through to some one who is less than compitent with there job. However with the steps that they do it is required before they can use any other protocols so unfortunately you would just have to bare with them.
Second of all if you would like to write in to complaint about a certain product or service, then you can do so in writing to our corespondence center the adress is as follows;
BT Correspondence Centre
Providence Row
Durham
DH98 1BT
Other alternatives for complaints are e-mailing in through the website via webform. http://bt.custhelp.com/app/contact_email/c/5642,5645 They aim to give a reply within 24-48 hours of receiving the form and will aim to do so satisfactory.
I hope i have been informative and it aids into the problem being fixed for yourself.
If this answer has helped please mark it up -
Troubles in dual boot system after BIOS update
Hello:
PC: Thinkpad T500
1. I had for one year Linux Fedora 10 and Vista Ultimate working in dual boot with Grub, no problems at all.
Three days ago Lenovo support recommended I update my BIOS from 2.07 to 3.12, as I had some intermitent Sleep problems in Vista. Then my problems started.
2. First, after updating the BIOS from Vista (dowloaded the exe, double clicked it, gone through the whole sequence with no errors), upon the first restart, the screen was black and I couldn't get in BIOS with F1 and the same happened during other power-off/power on sequences.
3. Now, I've discovered that the best I can do is wait for 10 min after restart in order to get a prompt from ThinkVantage, then Grub boots only the Linux system which works OK.
4. I can't get the dual boot message from Grub, and I can't get any Windows DVD to be taken at boot (I've got full backups from both Control Panel and from ThinkAdvantage backup facility) in order to ru Windows repair.
5. I can go during the ThinkAdvantage to BIOS, the new version seems there (not sure if completely operational), but whey can't I see it with F1?
Is the presence of ThinkAdvantage something special in dual-boot systems or wrt to the BIOS install? Should I do something special about it? I just don't know.
Any ideas?Strange. I don't have a clue, but I have seen posts here that recoverd from strangeness after a BIOS update by unplugging from the AC mains, removing the battery, and then pressing the power button several times. The last time, hold the button for 10 seconds or so.
That is really a total WAG, but maybe worth a try.
Out of curiousity, what do you see when grub finally loads. I take it that it isn't your original boot menu. Do you have grub installed in the MBR, the boot sector of the Linux partition, or both? Is the Linux partition (or Linux boot partition if you have boot + root) the 1st one on the drive, or _after_ the vista partition.
[edit] You didn't ask, but IMNSHO multibooting a modern laptop isn't really the easiest way to run multiple OSs. I run Linux, Solaris, and OS X in VMs under Win 7 on my T400. They run well, and that approach avoids issues like you are having. The Lenovo ThinkVantage boot-time stuff and R&R are rather fragile. Changes in partitioning and MBR configuration can break them. BIOS and other updates, and Windows repairs can break the multi-boot setup.
There are several ways to set up VMs, but VMWare Player is what I use. The latest version is free and quite usable.
Z.
The large print: please read the Community Participation Rules before posting. Include as much information as possible: model, machine type, operating system, and a descriptive subject line. Do not include personal information: serial number, telephone number, email address, etc. The fine print: I do not work for, nor do I speak for Lenovo. Unsolicited private messages will be ignored. ... GeezBlog
English Community Deutsche Community Comunidad en Español Русскоязычное Сообщество -
Brazilian Palm Centro firmwre upgrade
Hi,
a few years ago Palm released an update for the brazilian version of Palm Centro that solved an intermitent freezing problem whit incoming calls.
I have the files needed to upgrade the ROM but I forgot how to start the Palm Centro from SD Card as the updating procedures says that we need to copy all the files to a SD Card and start the phone from the card.
Can anyone here tell me how to start the Palm Centro from SD Card?
This question was solved.
View Solution.Try this Palm/HP Knowledgebase article:
http://kb.hpwebos.com/wps/portal/kb/common/article/5919_en.html
It happens to be for Sprint phones, but the memory card update procedure is detailed. Hope that does it for you
smkranz
I am a volunteer, and not an HP employee.
Palm OS ∙ webOS ∙ Android -
Fax failure in hairpinned configuration
We have a PGW call-controlled setup for voice. Most of the bearer channels terminate on AS5850's. Clients connected through PRI's are experiencing intermitant Fax problems. Some destinations fail, others send only a header and still others are successful but the image is garbled.
Since most of the calls are hairpinned on the AS5850, I don't know what exactly is causing this problems. Voice calls are successful.
Any ideas on how and where to look for the problem? I have run out of ideas.Hi!
There should no slips on the whole path of your voice/fax. Please look at http://www.cisco.com/en/US/tech/tk713/tk628/technologies_tech_note09186a008014f8a6.shtml how to set a proper clock synchronization.
Regards,
Ivan -
P35 PLATINUM sata performance issue.
p35 plat
c2d 6850
2 x maxtor 200 gig sata 2 drives
1 seagate 320 gig sata 2 drive
4 gig 1066 mem
winxp32 sp 2
Hi all, I'm on my second p35 as my first one died due to a duff mem slot and I think this ones developed a fault to. Up until about 3 weeks ago the board and 3 individual sata 2 drives have performed flawlessly but then while burning a dvd with nero the buffer emptied and the disk failed. I also noticed that winrar extraction of dvdr in .rar format that normally takes 1min 25 secs to unrar to a drive was taking as long as 4 minutes if not more.
The normal sata performance seems to have halved for no apparent reason, hdd tach was reporting problems with 2 drives but these have now disappeared. It seems like there is a problem but I cant pin it down to one specific thing because the system runs fine other than that. No crashes, bosd's or anything else; just really crap hdd drive performance when transferring files and and unraring file between the drives.I'm even seeing cyclic redundancy errors from my hdd when transferring files. I have just tried encoding a dvd image [ on 1 drive to another ] using dvdshrink and where in the past I would see 40,000kbs speed now it crawled along at 19,000.
So is my sata contoller on the board broken/failing and how can I test it to prove it? Thanks in advance people.The system ran fine for weeks with no probs. Same psu no change [ enermax is not a cheap generic psu plus its a carry over from my old sytem that ran 2 7800 gtx's in sli with the same hdd's]. I find it hard to believe that sustained data transfer between drives would be a psu issue all of a sudden. Burning a dvd to disk would not be an excessive power drain, that was the first time the fault maifested itself. Also that was the only thing happening at the time. Im not a multi tasker, one thing at a time. I do appreciate you guys throwing idea's my way. I'm hedging towards an intermitent hdd problem but as its not all the time its going to be a bugger to pin down as which drive it is. I would love it to be as simple as a dodgey hdd as otherwise how do you recreate a sata controller issue when faulting a mobo
-
Hi all,
I would like to parse a time (00:00:00) in String format into a Date obj. I am using the following code to achieve it. however, the result come out is not what i expect.
String fromTimeStr = "00:00:00";
TimeZone sg = TimeZone.getTimeZone("Asia/Singapore");
System.out.println("Timezone "+sg);
SimpleDateFormat DF = new SimpleDateFormat("HH:mm:ss");
DF.setTimeZone(sg);
Date time = DF.parse(fromTimeStr);
System.out.println("DAte time"+ time);the output is as followed:
Timezone sun.util.calendar.ZoneInfo[id="Asia/Singapore",offset=28800000,dstSavings=0,useDaylight=false,transitions=8,lastRule=null]
DAte timeThu Jan 01 00:30:00 GMT+08:00 1970
From what i know, the timezone of Singapore is fallen within the GMT+8 zone; thus the result should be Jan 01 00:00:00 GMT+08:00 1970
My system timezone is "Kuala Lumpur\Singapore GMT+8".
Could someone enlighten me what there is 30 minutes extra from the output.
Thanksjnaish wrote:
This is basically what I'm doing:
package test;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateFormatError
private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
private Date dateOfBirth;
public static void main(String[] args)
DateFormatError x = new DateFormatError();
x.run();
public void run()
String dob = "10/06/1989";
try
dateOfBirth = sdf.parse(dob);
catch (Exception e)
sdf.format(dateOfBirth);
System.out.println(dateOfBirth.toString());
}Edited by: jnaish on Feb 4, 2009 12:07 PMHey jnaish, thanks for the SSCCE, but your problem is probably already resolved after phdk's post. Just a small side note: never "swallow exceptions". Never ever! To "swallow an exception" is this:
try {
// something that may throw an exception
} catch(AnException e) {
// do nothing with it: ie, swallow it
}because whenever something goes wrong, you will not notice it since nothing is even printed to the screen: this makes debugging your code very hard! Always at least print the stack trace:
try {
// something that may throw an exception
} catch(AnException e) {
e.printStackTrace();
}so you will see some helpful message on your screen when something goes wrong.
Good luck! -
Problem parsing SimpleDateFormat date format to database
I have a page where I am getting parameter values form another page a constucting
a string from these values which i then want to insert into my SQL database.
The field i am putting the data into is of type DATETIME and i am using the SimpleDateFormat to format the string.
Here is my code
String startTime = request.getParameter("startHour") + ":" + request.getParameter("startMin")+ ":00";
String endTime = request.getParameter("endHour") + ":" + request.getParameter("endMin") + ":00";
String startDate = request.getParameter("startDay") + "-" + request.getParameter("startMonth") + "-" + request.getParameter("startYear");
String endDate = request.getParameter("endDay") + "-" + request.getParameter("endMonth") + "-" + request.getParameter("endYear");
scheduleData.startTime = startTime;
scheduleData.endTime = endTime;
scheduleData.startDate = startDate;
scheduleData.endDate = endDate;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
StringBuffer start = new StringBuffer();
start.append("'"); // start quote (enclose string values in single quote)
start.append(scheduleData.startDate); // or compose it from the parameter values
start.append(" "); // add space between date and time
start.append(scheduleData.startTime); // or compose it from the parameter values
start.append("'"); // end quote (enclose string values in single quote)
StringBuffer end = new StringBuffer();
end.append("'"); // start quote (enclose string values in single quote)
end.append(scheduleData.endDate); // or compose it from the parameter values
end.append(" "); // add space between date and time
end.append(scheduleData.endTime); // or compose it from the parameter values
end.append("'"); // end quote (enclose string values in single quote)
Date startSQLDate = new Date();
startSQLDate = sdf.parse(start.toString());
Date endSQLDate = new Date();
endSQLDate = sdf.parse(end.toString());
Driver DriverinsertSchedule = (Driver)Class.forName(MM_connAdministration_DRIVER).newInstance();
Connection ConninsertSchedule = DriverManager.getConnection(MM_connAdministration_STRING,
MM_connAdministration_USERNAME,
MM_connAdministration_PASSWORD);
for (int i = 0; i < scheduleData.participants.length; i++) {
PreparedStatement insertSchedule =
ConninsertSchedule.prepareStatement("INSERT INTO Administration.schedule (Assessment_ID, Participant_ID, Schedule_Name, Restrict_Times, Schedule_Starts, Schedule_Stops, Resrict_Attempts, Max_Attempts) VALUES ( '"
+ scheduleData.assessmentID + "', '"
+ scheduleData.participants[i] + "', '"
+ scheduleData.scheduleName + "', '"
+ scheduleData.participants[i] + "', '"
+ scheduleData.scheduleName + "', '"
+ scheduleData.timeLimit + "', '" + startSQLDate
+ "', '" + endSQLDate + "', '"
+ scheduleData.limitAttempts + "', '"
+ scheduleData.attemptsAllowed + "' ) ");
insertSchedule.executeUpdate();
}I am getting this error.
javax.servlet.ServletException: Unparseable date: "'01-01-2005 09:00:00'"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758) org.apache.jsp.administration.schedules.process_005fschedule_jsp._jspService(process_005fschedule_jsp.java:385)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.text.ParseException: Unparseable date: "'01-01-2005 09:00:00'"
java.text.DateFormat.parse(Unknown Source) org.apache.jsp.administration.schedules.process_005fschedule_jsp._jspService(process_005fschedule_jsp.java:133)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Can someone please help me as my project deadline is 2morrow and this is a major problem that needs fixing. Can anyone please tell me what i am doing wrong and how to fix the problem.
Help would be much appreciated
ThanksCan someone please help me as my project deadline ...You can do one of the following.
1. Figure out the exact format for time that your database takes. In the previous thread you posted there was a suggestion about that exact format.
2. Use prepared statements and a java.sql.Timestamp which was also suggested to you in the previous thread you posted.
3. Give up. -
New problems with simpledateformat
sorry guys to my previous post i had solved the issue of formatting my date format..
but i have a new problem now is that when i enter the 13 mnth 2006 simpledateformat auto helped me rectify to jan of 2007.. and i look through the simpledateformat class it does not have any methods to help me check the validity of the date i am inputting.. is there any other class i have to use to check the validity??hmm SimpleDateFormat doesn't have a set lenient
method only calendar has that...Scroll down some more. -
Problem with SimpleDateFormat (CommandLine vs WebApp)
Hello Friends,
I have a strange problem. Not sure what is the mistake from my side. I have simple class that returns formatted date based on TimeZone. It gives me different result if run on command line vs when used in web app. Below is the code & other information.
import java.util.*;
import java.text.*;
public class Test {
public static String getDateFormatted(String tZone) {
DateFormat dfm = new SimpleDateFormat("dd-MMMM-yyyy HH:mm:ss z");
dfm.setTimeZone(TimeZone.getTimeZone(tZone));
return dfm.format(new Date());
public static void main(String ar[]) {
System.out.println(getDateFormatted(ar[0]));
Output From Command Prompt
java Test PST
06-October-2008 20:37:01 PDT
Output From webapp running on Weblogic Server Version 10.0
06-October-2008 23:37:04 GMT-04:00
Java version from my command prompt
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)
To confirm if this problem is due to JRockit that is used as default for Weblogic, I changed Java Home in setDomainEnv.cmd to Sun JDK. But still no luck.
set BEA_JAVA_HOME=C:\bea\jrockit_150_11
set SUN_JAVA_HOME=C:\bea\jdk150_11
if "%JAVA_VENDOR%"=="BEA" (
set JAVA_HOME=%SUN_JAVA_HOME%
) else (
if "%JAVA_VENDOR%"=="Sun" (
set JAVA_HOME=%SUN_JAVA_HOME%
) else (
set JAVA_VENDOR=Sun
set JAVA_HOME=C:\bea\jdk150_11
Thanks & Appreciate any suggestionshow are you getting the tZone in web application?
are you taking it from the request?
in that case the timezone will be according to the settings in the browser. -
Problem with SimpleDateFormat.parse()
Hello
I have a problem with the parse-function in SimpleDateFormat.
When i try to parse the date Fri Jul 15 17:23:41 2005 with this pattern EEE MMM d HH:mm:ss yyyy i get the exception java.text.ParseException: Unparseable date: "Fri Jul 15 17:23:41 2005".
This is my code:
SimpleDateFormat df=new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy");
try {
df.parse(strDate);
} catch (ParseException e) {
e.printStackTrace();
}Can someone explain me what i did wrong?
Thanks
MatthiasSince your name is "Matthias" it is possible that your locale is one that does not use the English language. If that is the case then your problem is that "Fri" or "Jul" are not correct abbreviations in your language.
Easiest way to test this idea is to format a date (such as now) using that SimpleDateFormat object and see what the output looks like. -
SimpleDateFormat.parse() Problem
My Code:
public class Sdf {
public Sdf() {
SimpleDateFormat s1 = new SimpleDateFormat("DD:MM:yyyy:HH:mm:ss:a:z");
try{
Date myDate = s1.parse("15:11:2006:21:12:13:PM:GMT");
System.out.println(myDate.toString());
catch(Exception ex){
System.out.println("EX");
public static void main(String s[]){
new Sdf();
}The output: Sun Jan 15 21:12:13 GMT 2006
My Problem
The month entered in the parse method is 11 (Nov) but parsing returns January.
I am doing something wrong obviously, so what do I need to do to fix this?
My goal is to get a long value from that string pattern.
Thanks so much, for any help you can give.Hmm, when you think about it, the whole operation is extremely complicated anyway. Accounting for leap years, leap seconds daylight saving times, locale specific stuff and of course 'bad' entry�s such as Jan 32nd.
I spent hours trying to fix that problem. Manually calculating values by multiplying 1000*60*60 for hours, 24 hour time V's 12 hour time was another source of compilcation etc. I pretty much opened a can of worms that I wanted to close quite quickly again.
Some values I'd imagine would have to take precedence over others to limit the many combinations and permutations. What takes precedence over what is another story but I guess reading the API more carefully would eliminate the need to know such things for most purposes.
I certainly won't be forgetting the difference between DD and dd again in a hurry.
Thanks Again. -
Is there a problem on the pattern of SimpleDateFormat to parse a String ?
Hello,
I tried to parse a String to a Date using a SimpleDateFormat.
I must be able to have on the pattern something like : "yyyyMMdd_HH00".
To get a String from a Date with SimpleDateFormat.format(Date date) it works well, but when a try to parse a String into a Date with SimpleDateFormat.parse(String date) I get a : java.text.ParseException: Unparseable date.
I try it on a JVM 1.4 and 1.5 for the same result.
An exemple of code :
String pattern = "yyyyMMdd_HH00";
SimpleDateFormat currentFormat = new SimpleDateFormat(pattern);
Date date = currentFormat.parse("20091223_1000");It seems that adding the '00' after 'HH' raise the exception...
Has the 'HH00' a particular meaning like on Oracle 'HH24' ?
Is there a way to add number after the 'HH' ?
Thanks
Edit :
Oh yeah, I forgot, I tryied to use the pattern "yyyyMMdd_HH'00'" using '' to escape the 00 without better result...
Edited by: Jeremy.Antonucci on 23 déc. 2009 15:25The context of this pattern :
To get a file on a http server, I must build an Url String with a filename using the current date.
I want to be able to change easily the pattern on a file parameters.
The date must be ending with 00 for the minutes.
I may have use a pattern with 'HHmm' and suppress the minutes but if it is change on the futur the code will not work...
As I can't say if in the futur the url will change for the date pattern or not, I decide to use a pattern like "yyyyMMdd_HH00" that works fine for everything else than parsing a string.
I create a String date based on the current date on UTC using this pattern and keep it to use it to compose an Url String.
After I need to know how much time I must sleep before the next execution (on each Hour), so I use this date +1 hour to see if the currentDate during this calculation is higher than this date+1... (I'm surely not clear, but it is not the real problem just for curious ^^)
A dirty solution is to avoid this problem is to catch this case and do substitution on a temporary pattern of the 'HH00' with 'HHmm'. It's really dirty because nothing says that later a 'HH00' mean always 'HHmm' but I have nothing better...
String pattern2 = pattern;
if (pattern.matches(".*HH00$")) {
pattern2=pattern.substring(0, (pattern.length()-2))+"mm";
}Where can I do this bug report ?
Do you see a good solution ? -
SimpleDateFormat and TimeZone problem
Hi all, I know there have been a lot of questions
concerning this topic, but I've looked over a lot
of messages and I think I've used all ideas provided,
yet still I can't fix my problem.
My problem concerns parsing a date from a HTTP
packet. I use the following code:
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss zzz");
sdf.setTimeZone(TimeZone.getDefault());
Date date = sdf.parse(packet.substring(exp_pos+9, endline));Most of the time this code works perfectly, however
from time to time the parse result is 12 hours of.
Instead of 14h the result is 2h. HTTP dates use a
24 hour time.
I'm using the JVM by Blackdown, version 1.3.1 on
Debian Linux 2.2.18. The timezone is configured
correctly in my os. I'm in GMT+1.
I'm not sure if this is a bug or if I have done something
wrong.
Any help would be greatly appreciated.
PeterLooks to me that your time format with lower-case "hh" tells it to use the 12-hour, not 24-hour format, and you're not including the am/pm indicator. So it's doing just what you're telling it to do. If you want 24-hour format, use "HH" instead of "hh".
Maybe you are looking for
-
How do i use variables for javascript pop up window?
hi, i want to open a popup window from flash, as advised before i used this line : getURL("javascript:NewWindow=window.open('imylink.html','title','width=890,height=660,left =10,top=5,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=Yes,full
-
Error Message during PO GR - Please enter a valid transaction Type
During the goods receipt movement 1010 of a Purchase Order, I am getting following error Message: "Please enter a valid transaction Type" I am not a Purchasing expert. Could please help? Thanks and regards.
-
Cannot connect to Database in SQL Developer - TIMEZONE errors
Cannot connect to any database get the following errors. Status : Failure -Test failed: ORA-00604: error occurred at recursive SQL level 1 ORA-01882: timezone region not found Tried change NLS settings to America (currently South Africa) but to no av
-
Photoshop CS6 background canvas flickers during use.
I bought Adobe creative suit 6 design standard yesterday. when using photoshop, the background canvas flickers and becomes transparent when i do things (zoom, erase, brush) I have followed the solution of changing the drawing mode to Basic, but it is
-
Is it possible to delete the purchase history in the App Store?
Is it possible to delete the purchase history in the App Store?