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.
Peter

Looks 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".

Similar Messages

  • SimpleDateFormat and TimeZone; is: +0200 but must be +02:00

    Hello,
    running this code ...
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
    System.out.println(sdf.format(new Date()));... outputs this line as expected ...
    2008-07-24T18:59:58+0200... but what i actually need is ...
    2008-07-24T18:59:58+02:00Note the additional colon in the time zone output: +02*:*00. How to get that format as described in http://www.w3.org/TR/NOTE-datetime ?
    Thanks!

    nclow wrote:
    CapM wrote:
    Yes, but it also added a "GMT", which is not allowed by the remote side (i need to format XML that follows certain restrictions).Then your problem has just become a bit larger. Read the difference between the z and the Z symbol in the sdf API documentation. What will you do when your timezone output is "EDT" as it is for me? You can't put a colon in that. You may have to do further parsing with a Z symbol to eliminate text from that output and just keep the numbers. You might want to just do a new SimpleDateFormat("Z") and then pass that to a custom parser which will manipulate it according to your requirements, then append it later.Well, i guess that one is graceful and pragmatic enough. Thanks for your suggestions @ all!

  • Date and Timezone problem...

    Hello,
    Please, can sombody explain me the following program
              long l = System.currentTimeMillis();
              for (int i = 0; i < 25; i++ ){
                   l = l - 86400000;
                   System.out.println(i+":"+new Date(l));
    Output:
    0:Tue Apr 23 09:26:15 CEST 2002
    1:Mon Apr 22 09:26:15 CEST 2002
    2:Sun Apr 21 09:26:15 CEST 2002
    3:Sat Apr 20 09:26:15 CEST 2002
    4:Fri Apr 19 09:26:15 CEST 2002
    5:Thu Apr 18 09:26:15 CEST 2002
    6:Wed Apr 17 09:26:15 CEST 2002
    7:Tue Apr 16 09:26:15 CEST 2002
    8:Mon Apr 15 09:26:15 CEST 2002
    9:Sun Apr 14 09:26:15 CEST 2002
    10:Sat Apr 13 09:26:15 CEST 2002
    11:Fri Apr 12 09:26:15 CEST 2002
    12:Thu Apr 11 09:26:15 CEST 2002
    13:Wed Apr 10 09:26:15 CEST 2002
    14:Tue Apr 09 09:26:15 CEST 2002
    15:Mon Apr 08 09:26:15 CEST 2002
    16:Sun Apr 07 09:26:15 CEST 2002
    17:Sat Apr 06 09:26:15 CEST 2002
    18:Fri Apr 05 09:26:15 CEST 2002
    19:Thu Apr 04 09:26:15 CEST 2002
    20:Wed Apr 03 09:26:15 CEST 2002
    21:Tue Apr 02 09:26:15 CEST 2002
    22:Mon Apr 01 09:26:15 CEST 2002
    23:Sun Mar 31 09:26:15 CEST 2002
    24:Sat Mar 30 08:26:15 CET 2002
    Why does does the Timezone change?
    CEST => CET????
    Any Ideas
    Greeting & Thanks
    Peter

    CEST means Central European Summer Time.
    CET means Central European Time.
    Is has something to do with the summer time.

  • Gnome clock and timezone problems

    When I run "date" in the terminal, it says "Wed Sep  3 20:56:39 CST 2008" even though I'm in australia/adelaide. I try setting the timezone from right-clicking the gnome clock, but after I login/out, it just resets to "America/Indiana/Tell City"
    Help?

    I also recommend using ntp.

  • Help with SimpleDateFormat and time

    Hi,
    I have a strange result when formating a time!
    Time test = new Time(0);
    DateFormat df = new SimpleDateFormat("HH:mm:ss");
    System.out.println("my date: "+ df.format(test));
    Result is 01:00:00
    Why is this not 00:00:00
    Thanks in advance,
    Pieter

    A Date object represents a moment in time, which can have different textual representations. A Date is represented in Java by a number of milliseconds counted from a fixed moment in time: 00:00 UTC on January 1, 1970 AD (using the Gregorian Calendar), which is the same as 01:00 CET. If that is not the time you mean, you should create a date with a different number of milliseconds (or better yet: use the Calendar class to specify the exact date, time and timezone you mean).
    It doesn't matter what timezone the server is set to or what timezone anything is set to, the Date still represents the same moment in time. The only time it matters is when you want to output a Date for a human to read. If you want everyone to just see the same numbers, explicitly set the timezone on your DateFormat to something fixed (I recommend "UTC" over anything else). Just make sure everyone understands which timezone you use.
    Storing the time as seconds will not help - it already stored as (milli)seconds anyway - nor will any other kind of converter: (Simple)DateFormat already has the capabilities to "convert" Strings to and from Date objects (note that using a DateFormat does NOT change the date in any way, it just displays/parses the date in an appropriate format/timezone).

  • Iphone subscribed calendar - basic authentication, events and timezone

    hi,
    i'm attempting to use the subscribed calendar feature in iOS and having problems.
    1st issue: i've put an ics file that regularly gets updated on an at a web location that is basic authentication protected. Inside the subscribed Calendar settings there is a place to put username and password. When i click "Done" and iOS tries to verify the information, i get a popup saying "account requires a username and password"... I know basic authentication works and the username and password are correct because i've tested via browser and very simple passwords e.g. 123.
    2nd issue: I do work with people in other timezones and so i frequently get meeting requests from people in other timezones. In the ICS file i can see this information is published appropriately. e.g.
    DTSTART;TZID="Romance Standard Time":20110510T170000
    DTEND;TZID="Romance Standard Time":20110510T183000
    If I import this ics file into google calendar, the timezones are read appropriately and the meetings are scheduled accordingly. in the example above, the meeting shows up as being at 8am - 9:30am.
    on iOS the timezone is completely ignored. so i get the meeting showing up as 5pm - 6:30pm.
    I've tried fiddling with the "Time Zone support" option in settings, but this does nothing.
    Help on the issues above is greatly appreceiated. Personally I'm extremely frustrated with this.
    Thanks

    ...Thought I would keep alive the question about incorrect times for appointments created in other time zones on subscribed calendars. I believe this other thread -- https://discussions.apple.com/message/17318550#17318550 -- is asking about the same issue.
    I am experiencing the same issue, including the setting for Time Zone Support having no impact, with iOS 6.
    Any whiff of a solution yet?

  • SimpleDateFormat and Timestamp does not exist in the 1.6 JDK (1.6.0_18)

    I am trying to compile a program with SimpleDateFormat and I get "cannot find symbol". I'm using Netbeans and Maven and in Netbeans, the software finds the correct import java.text.SimpleDateFormat, so it's not a question of the definitions not being there, it's the compiled classes that are missing somehow.
    Any ideas what could be the problem?
    My classpath: CLASSPATH=.;C:\Program\Java\jdk.1.6.0_18\jre\lib\resources.jar;C:\Program\Java\jdk1.6.0_18\jre\lib\rt.jar;C:\Program\Java\jdk1.6.0_18\jre\lib\sunrsasign.jarI reinstalled both netbeans and the JDK (after first uninstalling them, then removing any remaining files manually and then rebooting my computer).
    This simple application demonstrates the problem:
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    public class DatabaseBuilder
        private DateFormat m_formatter;
        public DatabaseBuilder()
            m_formatter = SimpleDateFormat( "yyy-MM-dd HH:mm:ss" );
    }Resulting output:
    DatabaseBuilder.java:10: cannot find symbol
    symbol  : method SimpleDateFormat(java.lang.String)
    location: class DatabaseBuilder
            m_formatter = SimpleDateFormat( "yyy-MM-dd HH:mm:ss" );
                          ^
    1 error

    dh-at-cross wrote:
    On the internet it is easy to be misunderstood and to me your message came across much more "read the error message, stupid" than you intended I just wanted to let you know.I'm aware that it's easy to be mis-understood on the internet. But to be totally honest: that's a risk, I'm willing to take.
    The alternative is to be extremely polite in every post and add an extensive disclaimer describing my very intent in addition to the pure technical discussion.
    But I choose not to do that (and thus tolerate a (hopefully) small number of people who are offended by me) for several reasons:
    - I'm to lazy to write that disclaimer
    - writing it would cost time, which I can use better for helping others or getting some work done
    - writing that disclaimer would give people the impression that it will always be that way, but it's not true: you'll have to be able to deal with technical criticism in the technical world
    - if someone wants to feel offended, they will find a reason, no matter how polite I am

  • IPod touch keeps changing the date, time, and timezone on its own

    Yesterday I noticed that the iPod was showing the wrong date, so I fixed it. I also checked the computer I was syncing to, but it had the correct date, time, etc. Now when I woke up the iPod today, the time, date, and timezone had all been changed again. Has anybody else had this problem, or know what I need to do to stop it? Thanks!

    When you sync the iPod, you have to sync it with a "new" iTunes window.
    Before you connect the iPod, exit out of iTunes, then reload it, and finally connect your iPod to it.
    I believe there was a software update that fixed this...

  • I am not able to launch FF everytime i tr to open it, it says FF has to submit a crash report, i even tried doing that and the report was submitted too, but stiil FF did not start, and the problem still persists, please help me solve this issue in English

    Question
    I am not able to launch FF everytime i try to open it, it says FF has to submit a crash report,and restore yr tabs. I even tried doing that and the report was submitted too, but still FF did not start, and the problem still persists, please help me solve this issue
    '''(in English)'''

    Hi Danny,
    Per my understanding that you can't get the expect result by using the expression "=Count(Fields!TICKET_STATUS.Value=4) " to count the the TICKET_STATUS which value is 4, the result will returns the count of all the TICKET_STATUS values(206)
    but not 180, right?
    I have tested on my local environment and can reproduce the issue, the issue caused by you are using the count() function in the incorrect way, please modify the expression as below and have a test:
    =COUNT(IIF(Fields!TICKET_STATUS.Value=4 ,1,Nothing))
    or
    =SUM(IIF(Fields!TICKET_STATUS=4,1,0))
    If you still have any problem, please feel free to ask.
    Regards,
    Vicky Liu
    Vicky Liu
    TechNet Community Support

  • BOSD, Battery issues and Heating problem after iOS 8 upgrade

    i have upgraded my iPad mini to iOS 8. Ever since I upgraded to iOS 8 am facing blue screen issues and heating problem as well. This is really frustrating even the patch iOS 8.0.2 dint solve the problem. Are you guys listening our complaints. When will you fixing it.

    The same thing happened to me on my 2012 Subaru Outback.  I'm not sure this will help you since you have a Honda, but I'm posting this just in case.
    I paired the audio on my car with my iPhone 6.  However, when I turned the car off and back on again, the iPhone would not pair automatically.  I had to manually connect the iPhone with the car.  Turns out there are two separate bluetooth pairings on my car: one for phone which allows up to 5 devices and one for audio which allows only one device.  So I did the second bluetooth pairing for the phone (had already done the audio), and that fixed it.  YMMV

  • I am making code to try to make a game and my problem is that my code......

    I am making code to try to make a game and my problem is that my code
    will not let it change the hit everytime so im getting the first guy to hit 1 then next hits 8 and so on and always repeats.
    Another problem is that I would like it to attack with out me telling it how much times to attack. I am using Object oriented programming.
    Here is the code for my objects:
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.Random;
    import static java.lang.Math.*;
    import java.awt.*;
    import java.awt.color.*;
    class rockCrab {
         //Wounding formula
         double sL = 70;                                   // my Strength Level
         double bP = 1;                                   // bonus for prayer (is 1 times prayer bonus)
         double aB = 0;                                 // equipment stats
         double eS = (sL * bP) + 3;                         // effective strength
         double bD = floor(1.3 + (eS/10) + (aB/80) + ((eS*aB)/640));     // my base damage
         //Attack formula
         double aL = 50;                                   // my Attack Level
         double eD = 1;                                   // enemy's Defence
         double eA = aL / eD;                              // effective Attack
         double eB = 0;                                   // equipment bonus'
         double bA = ((eA/10) * (eB/10));                    // base attack
         //The hit formula
         double fA = random() * bA;
         double fH = random() * bD;
         double done = rint(fH - fA);
         //health formula
         double health = floor(10 + sL/10 * aL/10);
         rockCrab() {
         void attack() {
              health = floor(10 + sL/10 * aL/10);
              double done = rint(fH - fA);
              fA = random() * bA;
              fH = random() * bD;
              done = rint(fH - fA);
              System.out.println("Rockcrab hit" +done);
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.Random;
    import static java.lang.Math.*;
    import java.awt.*;
    import java.awt.color.*;
    class self {
         //Wounding formula
         double sL = 1;                                   // my Strength Level
         double bP = 1;                                   // bonus for prayer (is 1 times prayer bonus)
         double aB = 0;                                 // equipment stats
         double eS = (sL * bP) + 3;                         // effective strength
         double bD = floor(1.3 + (eS/10) + (aB/80) + ((eS*aB)/640));     // my base damage
         //Attack formula
         double aL = 1;                                   // my Attack Level
         double eD = 1;                                   // enemy's Defence
         double eA = aL / eD;                              // effective Attack
         double eB = 0;                                   // equipment bonus'
         double bA = ((eA/10) * (eB/10));                    // base attack
         //The hit formula
         double fA = random() * bA;
         double fH = random() * bD;
         double done = rint(fH - fA);
         //health formula
         double health = floor(10 + sL/10 * aL/10);
         self() {
         void attack() {
              health = floor(10 + sL/10 * aL/10);
              fA = random() * bA;
              fH = random() * bD;
              done = rint(fH - fA);
              System.out.println("You hit" +done);
    }Here is the main code that writes what the objects do:
    class fight {
         public static void main(String[] args) {
              self instance1 = new self();
              rockCrab instance2 = new rockCrab();
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
    }when the code is run it says something like this:
    you hit 1
    RockCrabs health is 9
    RockCrab hit 7
    your health is 38
    you hit 1
    RockCrabs health is 8
    RockCrab hit 7
    your health is 31
    you hit 1
    RockCrabs health is 7
    RockCrab hit 7
    your health is 24
    you hit 1
    RockCrabs health is 6
    RockCrab hit 7
    your health is 17
    my point is whatever some one hits it always repeats that
    my expected output would have to be something like
    you hit 1
    RockCrabs health is 9
    RockCrab hit 9
    your health is 37
    you hit 3
    RockCrabs health is 6
    RockCrab hit 4
    your health is 33
    you hit 2
    RockCrabs health is 4
    RockCrab hit 7
    your health is 26
    you hit 3
    RockCrabs health is 1
    RockCrab hit 6
    your health is 20
    Edited by: rade134 on Jun 4, 2009 10:58 AM

    [_Crosspost_|http://forums.sun.com/thread.jspa?threadID=5390217] I'm locking.

  • Remote and IR Problem

    A rather odd and annoying problem has recently been occuring on my MBP. A couple days ago my remote (after working without fail for over a year now) suddenly stopped working. Yesterday night and this morning it started working again but after a while it stopped again. I've read dozens of support articles which haven't really helped because there seems to be another problem.
    Most articles have stated that there is an option to disable the IR receiver in the "security" window under system preferences. When the IR and remote are not working this option disappears but when they are working the option is present. I have also tried replacing the battery without any result.
    I am now thinking that it might have something to do with heat buildup because it is mainly occuring after the laptop has been on for about a half hour, so I am going to try to borrow someone's fan.
    If anyone has any suggestions to solve this I would appreciate it if you could help. Thanks!
    MacBook Pro 1.83 GHz   Mac OS X (10.4.9)  

    check out this thread. Seems to be the same problem.
    http://discussions.apple.com/thread.jspa?messageID=4701905&#4701905

  • LG Ally text message and gps problems

    hello. ive been with verizon for about 10 years maybe. ive been overall happy with the service and customer service. but the prices should be alot lower.lol. i started out with the motorolas then switched to the lg phones. only problem with the motorola was the speakers. not loud enough. could never hear the phone ring. the lgs usually suffer from the same problem.
    i had a few phone problems but nothing like this lg ally. im on my second one and about to be my 3rd one in about 3 months. 1st phone i had every problem under the sun. this phone i am suffering from text message problems and gps problems. i suffer from what everyone else has problems with. the messages wont send. they will eventually lock up. it will show the envelope with the red explanation point ( i think thats the graphic). then usually everytime when i sent a text the texts will close. it will send then bounce back and show up as a draft and i have to resend it and wait for it to go thru. finally the last problem with the texts. when i send a text a phone number from my contacts shows up and freezes on the screen. its in white text with a black background. its the same number every time. it stays on the screen until i restart or pull my battery out.
    gps. when i open up google gps that comes with the phone i make sure the gps is on... when the directions are found and the map pops up 9 out of 10 times it just keeps saying searching for gps. the turn by turn never is found. the 1 time it does it takes a good 10 minutes to be found. atleast on my first one ally the gps did work 8 out of 10 times. it just took a good 5-10 minutes for gps to be found and show turn by turn.
    anyone else have these problems? where you able to fix them or did you need to get a new phone? the 2.1 update was supposed to fix problems. i think they just made it worse. the ally is supposed to have 2.2 froyo. where is it. is it ever going to get it. i got this phone because i like the lgs and the keyboard. also the sales representative on the phone was giving the lg ally rave reviews. why couldnt he say dont buy this go with a motorola droid. this phone is the biggest junk ever made

    I do apologize you are having trouble with your device I looked in our information system on the LG Ally in reguards to issues you are having it states if you have the Free Droid Security anti virus protection application down loaded it will cause the phone to lock up or freeze. Check and make sure you do not have the application on your device. Check you GPS settings and make sure correct. Go to Settings; Location & Security; make sure GPS is on wireless network. If this does not fix issue you can try doing a Master Reset on your device. Make sure your contacts are saved in your G-mail account or through Back Up Assistance.
    Master Reset/Soft Reset:
    Factory Reset option 1
    From the main screen, touch menu tab
    Touch Settings
    Touch Privacy
    Touch Factory Data reset
    Touch Reset Phone
    Warning: This will erase all data from your phone, including:
    Your Google account
    System and application data and settings
    Downloaded Applications
    It will not erase: Current System software and bundled applications; SD Card files, such as music or Photos
    Factory Reset option 2  - Warning this will reset device back to original factory settings.
    Turn off the phone
    Press and hold "home" + "end" + "volume up or down" keys together for a few seconds when the device is power off
    Once device displays boot information, release keys.
    Soft Reset
    Press the Power key.
    Touch Power off.
    Touch OK.
    Press the Power key to power on the device.
    or
    Remove battery cover, remove battery and reinstall.Also there is a new update for LG Ally it will be the Froyo 2.2 but there is not release date available at this time it will post on your device when available. Hope this Helps. Leslie

  • I am deleting files through my trash in my macbook pro (2010) and then emptying the trash can, but my hard disk space is not increasing! i recently upgraded to lion and the problem is new, wasn't the same with snow leopard! HELP!!!!!

    i am deleting files through my trash in my macbook pro (2010) and then emptying the trash can, but my hard disk space is not increasing! i recently upgraded to lion and the problem is new, wasn't the same with snow leopard! HELP!!!!!
    When i press command+I (Get Info) i see that there is 140 GB "Available Space" on my hard disk but when i click on my hard disk icon on the desktop, and then press "space" i only see 102 GB free!! What the f*???
    Please HELP!!!!!! Getting second thoughts on Lion!!!!

    Hi b,
    Have you restarted yet?

  • How do I fix my ipod classic that says very low batter after I have charged it and the problem persists?

    I have an Ipod video 30g that says Please wait very low battery. I charged it for about a day and the problem persists. I've tried using some solutions on the internet and none of them worked including: holding the menu and select, holding select and play to put it in disk mode with no avail. Is there anyone who can help me!!!

    Have you read this post written by another forum member?
    The Sad iPod icon.
    However, as your iPod was purchased on Boxing Day, why not get it serviced under the warranty?
    You can arrange online service here.
    Service request.
    Or if an Apple store is near you, take it there and have them check your iPod.
    You can make an appointment by using this link.
    Genius Bar Appointments.

Maybe you are looking for

  • Recent windows 7 updates caused serious conflicts??

    I have two NI PCIe-1433 boards and the NI Max v5.4 installed. Recent win 7 (64 bit) automatic updates, within the last 10 days seemed to cause serious problems. Win 7 couldn't boot any more. Sometimes computer turns on and off by itself before the wi

  • Sims 3 freezing

    I have played Sims 3 on my MacBook Pro for the longest time.  But since I upgraded to Lion it has been freezing within 3 minutes of starting a game.  Has this happened to anyone else?  And does anyone know whats wrong/how to fix it?

  • HT4759 how can it get my ipad to connect to the wi-fi

    having trouble connecting my ipad to my wi-fi

  • Images shifting in Firefox

    Hi - I have a web page that I've developed from a template in Dreamweaver.  The page is loading perfectly in Safari and IE, but there's a small problem when using Firefox.  I think the problem is in the FLASH video I have on the page.  The video seem

  • HOW DO I GET BROWSERLAB TO APPEAR IN "PREVIEW IN BROWSER"?

    I HAD TO RE-INSTALL  DREAMWEAVER.  THE BROWSER LAB DISAPPEARED FROM THE "PREVIEW IN BROWSER" OPTION. I RE-DOWNLOADED THE PREFERENCE EXTENSIONS.  I CAN ACCESS THE ADOBE BROWSER LAB FROM SAFARI, BUT NOT FROM WITHIN DREAMWEAVER. SUGGESTIONS?