Calendar.HOUR_OF_DAY ok, wrong with Calendar getTimeInMillis

Hi! I've a very strange behaviour (at least for me) regarding getTimeInMillis from the Calendar class.
I have this code:
Calendar ahora = new GregorianCalendar(TimeZone.getTimeZone("Etc/GMT+6"),new Locale("es_MX"));
System.out.println(ahora.get(Calendar.HOUR_OF_DAY));
System.out.println(ahora.get(Calendar.DAY_OF_MONTH)+1);
System.out.println(ahora.get(Calendar.MONTH));
System.out.println(ahora.get(Calendar.YEAR));
java.util.Date f = ahora.getTime();
System.out.println(f.toString());And the output is:
14
10
10
2004
Sun Oct 10 20:24:59 GMT 2004
The strange thing, is that the Calendar.HOUR_OF_DAY prints the hour correctly (14) but the Date object says it is the hour 20. What tha hell is going on there? Why one print the hour correctly and the other don't! I supouse that it has something with the TimeZone in the Calendar class, but I don't know what exactly is going on.
Regards!

Hi bbritta! I used the SimpleDateFormat and the result is the same. I still get the right hour from Calendar.HOUR_OF_DAY but wrong from toString() from the Data object created with the milliseconds of the Calendar.
This is what I did after your post:
Calendar ahora = new GregorianCalendar(TimeZone.getTimeZone("Etc/GMT+6"),new Locale("es_MX"));
SimpleDateFormat formatter =     formatter = new SimpleDateFormat("h:mm a",new Locale("es_MX"));
java.util.Date f = ahora.getTime();
System.out.println(formatter.format(f));In fact, the behaviour is very strange. In Mexico City we are at GMT-6, but if I put that on the TimeZone of the Calendar, it always show a plus 12 hours. For example, right now we are 15:00 on October 10 in MexicoCity, if I use GMT-6 (in theory the right timezone), I get that is the hour 3 (AM) on October 11. But if I put GMT+6, I get the right hour and day from Calendar.XXXX but wrong from the millis.
Any other idea?

Similar Messages

  • How to use the method calendar.getTimeInMillis() and setTimeInMillis(bb)

    I have met some problems in writing my programme,I want to know what the time is after every 20 minutes so have written some codes as below ,but the compilar warned me that there are some errors in them ,and I don't know how to use them correctly ,can you help me?
    Thank you very much!
    the code is:
    begin=datime+" 00:00:00";
    Calendar calendar=Calendar.getInstance();
    DateFormat df = DateFormat.getDateInstance();
    Date start=df.parse(begin);
    calendar.setTime(start);
    long aa=calendar.getTimeInMillis();
    calendar.setTimeInMillis(aa);

    Hopefully the following snippet of code will help you out (note that the Date class seems more appropriate for what you need to do):
    import java.util.*;
    import java.text.*;
          String begin="00:00:00";
          SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
          df.setTimeZone(TimeZone.getTimeZone("GMT"));
          Date start=new Date();
          try {
             start=df.parse(begin);
          } catch (Throwable e) {
             System.out.println("Invalid time format");
          long aa=start.getTime();   // to get the time in milliseconds
          System.out.println(aa);    // just to see what the answer is (should be zero)
          start.setTime(aa);         // to set the time in milliseconds
    ...V.V.

  • TS1702 i if use "search" in music on my ipod touch 5th gen the result just show only album and playlist but nothing song result.whats wrong with it?please help

    i if use "search" in music on my ipod touch 5th gen the result just show only album and playlist but nothing song result.whats wrong with it?please help

    The users guide says:
    Spotlight searches the following:
    Contacts—All content
    Apps—Titles
    Music—Names of songs, artists, and albums, and the titles of podcasts and videos
    Podcasts—Titles
    Videos—Titles
    Audiobooks—Titles
    Notes—Text of notes
    Calendar (Events)—Event titles, invitees, locations, and notes
    Mail—To, From, and Subject fields of all accounts (the text of messages isn’t searched)
    Reminders—Titles
    Messages—Names and text of messages
    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Unsynce all music and resync
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup
    - Restore to factory settings/new iOS device.
    - Make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar

  • What is wrong with my ipod touch 2nd gen?

    Ive had this iPod since mid 2010. It's running iOS 4.2.1 and it's not jailbroken. A few months ago I encountered a problem with it. It started to fast forward my songs and pause them and skip them as if it had a mind of it's own. I thought it was a one off and it never really happened after that. Yesterday something happened to it which forced it into recovery mode and I had to restore it to factory settings. Today I added some new songs onto it and I starte listening and all I could hear was music and no singing, then I could faintly hear the singing. I thought there was something wrong with the song so I changed it and it was the same with the next one. I've tried 3 different sets of heaphones which all work on other devices so it's not the headphones. So my iPod has kind of turned into a karaoke machine but with some songs it works ok for a while but then messes up. Also I've noticed that the fastforwarding thing has become much much worse after I restored it.
    I'm really stuck. What should I do? Everything else works fine on it. All my apps are ok. Just the music player is stuffed. Could the headphone jack be broken? It worked fine yesterday before I restored it. Should I restore it again? I've already tried restarting and resetting it and neither of them worked. Also I don't have much space left on it, should I take off the movie that ive got on it? Maybe the memory is kind of choked up as well? Thanks for any help guys. As I said pretty much everything works fine on it and I'm trying to not buy a new iPod if I can help it. Oh and sometimes when I'm typing and press the backspace button once or twice it goes and deletes everything on it's own. Things run slow-ish as well. Anyway to improve that? 
    Oh and may I also add when I can hear the singing in the songs sometimes it's normal, sometimes it sounds like they're singing underwater, sometimes it sounds like they're singing live, sometimes it sounds like they're robots...it's not how the songs are meant to sound. They didn't sound like that before and they don't sound like that on my laptop. There's something wrong with my iPod but idk if it's the headphone jack or a software/hardware problem. :/ :(

    - Try cleaning out/blowing out the headphone jack. Try inserting/removing the plug a dozen times or so.
    Try the following to rule out a software problem
    - Reset the iPod. Nothing will be lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup
    - Restore to factory settings/new iPod.
    - Make an appointment at the Genius Bar of an Apple store. Seems you have a bad headphone jack.
    Apple Retail Store - Genius Bar
    Apple will exchange your iPod for a refurbished one for this price. They do not fix yours.
    Apple - iPod Repair price
    A third-party place like the following will replace the jack for less. Google for more.
    iPhone Repair, Service & Parts: iPod Touch, iPad, MacBook Pro Screens
    Replace the jack yourself
    iPod Touch Repair – iFixit

  • What is wrong with my facetime,i am using an ipad everytime i placed a call i can't hear it ringing and the person i am calling can't recieve my call as well,i did everything possible forced off my ipad,on and of facetime on settings,change id's.

    What is wrong with my facetime,i am using an ipad everytime i placed a call i can't hear it ringing and the person i am calling can't recieve my call as well,i did everything possible forced off my ipad,on and off facetime on settings,change id's, mute,unmuted,reset network settings!! But nothing change,i mean is there a problem with my ipad or the facetime has a problem right now?my friend seems doesnt have a problem with her ipad,it just happen suddenly yesterday it was ok but today when i tried calling my husband this is what happens, can anyone please help me!!

    - Try cleaning out/blowing out the headphone jack. Try inserting/removing the plug a dozen times or so.
    Try the following to rule out a software problem
    - Reset the iPod. Nothing will be lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup
    - Restore to factory settings/new iPod.
    - Make an appointment at the Genius Bar of an Apple store. Seems you have a bad headphone jack.
    Apple Retail Store - Genius Bar
    Apple will exchange your iPod for a refurbished one for this price. They do not fix yours.
    Apple - iPod Repair price
    A third-party place like the following will replace the jack for less. Google for more.
    iPhone Repair, Service & Parts: iPod Touch, iPad, MacBook Pro Screens
    Replace the jack yourself
    iPod Touch Repair – iFixit

  • What is wrong with my headphone jack? i have an ipod touch 4th generation ipod touch every pair of headphones and earbuds i plug in it has the same sound going to both sides.

    what is wrong with my headphone jack? i have an ipod touch 4th generation ipod touch every pair of headphones and earbuds i plug in it has the same sound going to both sides.

    - Try cleaning out/blowing out the headphone jack. Try inserting/removing the plug a dozen times or so.
    Try the following to rule out a software problem
    - Reset the iPod. Nothing will be lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup
    - Restore to factory settings/new iPod.
    - Make an appointment at the Genius Bar of an Apple store. Seems you have a bad headphone jack.
    Apple Retail Store - Genius Bar
    Apple will exchange your iPod for a refurbished one for this price. They do not fix yours.
    Apple - iPod Repair price                  
    A third-party place like the following will replace the jack for less. Google for more.
    iPhone Repair, Service & Parts: iPod Touch, iPad, MacBook Pro Screens
    Replace the jack yourself
    iPod Touch Repair – iFixit

  • Any idea what's wrong with my iPod I have a picture

    I'd like to give this to my dad so he'll have something to use for music any ideas how to fix it or atleast tell me whats wrong with it thanks you guys

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                 
    iOS: How to back up                             
    - Restore to factory settings/new iOS device.
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar          

  • Is there something wrong with my battery?

    Hi everyone! I have an Iphone 5 that was newly "remodeled" for tmobile. I was wondering if there was something wrong with my battery after a recent decline in performance. I am updated to the latest iOS and I recently restored all of my settings on my phone in an attempt to increase battery performance, leaving only wifi on location for weather. With my current usage and standby, do I have something to be concerned about? I know some individuals that have my usage and will have a standby time of over a day. Advice and opinions is very much appreciated.

    Usage and Standby the same means that there is an app on your phone that is running continuously. Usually its an app choking on bad data, or trying to send and failing. There are a few troubleshooting steps you can try:
    Mail is a common culprit, especially if you have a Microsoft Exchange email account. If you do, go to Settings/mail,contacts,calendar, tap on the Exchange account, and turn off the switches. Then back out of settings and restart the phone (hold HOME and SLEEP until an Apple logo appears). Then turn the switches back on. This clears the mail, contacts and calender queues. It will take a while to resync content, so don't check battery condition until the resync is finished. And its best to do this with a WiFi connection as a lot of data may go by.
    If that doesn't fix it do the same with your iCloud account, and any other Push accounts you may have (Yahoo, gmail, hotmail, AOL).
    Next, look for apps that run in background (most of the apps in the Quick Launch ribbon do not run in background, but a few do - music and video streaming apps, Facebook, Twitter, Yahoo Messenger, Whatsapp, etc). Kill them in the quick launch ribbon by pressing HOME twice to display it, then hold your finger on any app until they all wriggle, then tap the "-" on each one. It won't do any harm to kill them all.
    Note that if you have Google Maps installed and you asked it for directions it won't stop tracking you until you actually kill it in the Quick Launch ribbon.
    good luck and report back!
    BTW, you will see a lot of posts blaming some specific version, now 6.1.4 (because it's the newest). But you will see just as many reports for 6.1.3, 6.1.2, ...5.1,...4.1...3.0, etc. It's nothing wrong with the version (except for 2.1, which had a real bug), it seems to be caused for some people by the upgrade process itself. But there are also many people who encounter this symptom far away in time from any upgrade.

  • I'm trying to add the system date with a Label. What is wrong with the code

    import java.util.*;
    import javax.swing.*;
    public class CurrentDateApplet extends JApplet
         Calendar currentCalendar = Calendar.getInstance();
         JLabel dateLabel = new JLabel();
         JPanel mainPanel = new JPanel();
         int dayInteger = currentCalendar.get(Calendar.DATE);
         int monthInteger = currentCalendar.get(Calendar.MONTH)+1;
         int yearInteger = currentCalendar.get(Calendar.YEAR);
         public void init()
              mainPanel.add(dateLabel);
              setContentPane(mainPanel);
              dateLabel.append(currentCalendar.get(Calendar.HOUR) + currentCalendar.get
                        (Calendar.MINUTE);
    }

    As for what's wrong with the code, it would be easier if you said: it doesn't show the date (it does this instead), it doesn't compile (I get this message) etc.
    Anyway I'll assume you want to display the time in a label...
    dateLabel.append(currentCalendar.get(Calendar.HOUR) + currentCalendar.get
    (Calendar.MINUTE);This won't compile: the parentheses are mismatched, and there is simply no such thing as append(). So we could trydateLabel.setText("" + currentCalendar.get(Calendar.HOUR) + currentCalendar.get(Calendar.MINUTE));This wroks, but looks pretty nasty and it's not how you are supposed to format dates and times. Here's the unofficial party line, nicked from one of jverd's posts:
    Calculating Java dates: Take the time to learn how to create and use dates
    Formatting a Date Using a Custom Format
    Parsing a Date Using a Custom Format
    From those links you should be able to find those applicable to times like this: http://www.exampledepot.com/egs/java.text/FormatTime.html
    Using this approach you would end up with something like:import java.text.Format;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import javax.swing.JApplet;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class CurrentDateApplet extends JApplet
        private Date date;
        private JLabel timeLabel;
        private JPanel mainPanel;
        public void init()
            mainPanel = new JPanel();
            timeLabel = new JLabel();
            mainPanel.add(timeLabel);
            setContentPane(mainPanel);
            date = new Date();
            Format formatter = new SimpleDateFormat("HH:ss a");
            timeLabel.setText(formatter.format(date));
    }

  • What is wrong with the loop?

    What is wrong with the loop? I am trying to make the loop with start to end dates. What is wrong with those codes that
    I made:
          Calendar startLoop = new GregorianCalendar(2003, Calendar.SEPTEMBER, 01);
          Date datessss = startLoop.getTime();
          Calendar endLoop = new GregorianCalendar(2003, Calendar.SEPTEMBER, 05);
          Date datesssss = endLoop.getTime();
          int result = 0;
          while (endLoop.after(startLoop){
               startLoop.add(Calendar.DATE, 1);
               Date dates5 = startLoop.getTime();
               System.out.println("New Date: " + dates5);
          }Because I got an error those:
    while (endLoop.after(startLoop)Anybody know what is wrong with it?

    In general you'll get better help if you paste in the exact, complete error message.
    In this case it's easy. Count your parentheses.

  • My Ical is alternating colours (purple and blue) every time I attempt to add an event. What is wrong with my ical?

    My macbook pro is about 2 years old. Earlier today my ical started changing colors on it's own. I had not changed any setting or preferences.
    Could someone please tell me why this is happening?
    I am not bothered by it but I'm worried something is wrong with my mac book I have never had any problems with it before.
    Please help !

    Hi,
    From the iCal menu > Preferences > General tab and set the Default Calendar to "Last selected calendar".
    best wishes
    John M

  • RMBP: Sometimes, after having been shut down, i have to press the power button several times before the machine starts up. It's 3 weeks old, and this has happened 2 times now. Is there something wrong with my rMBP?

    rMBP: Sometimes, after having been shut down, i have to press the power button several times before the machine starts up. It's 3 weeks old, and this has happened 2 times now. Is there something wrong with my rMBP?

    Did you purchase the Mac new?
    You have 14 calendar days from the time your items are delivered to initiate a return as noted here.
    Even though you are past the 14 day limit, if it were me, I'd take the Mac back and explain what's going on. Your Mac should work out of the box.
    message edited by:  cs

  • My phone wont let me download anything even free stuff or update.it keep saying something wrong with my billing info so i fix it but still cant download.I signed out sign back in still nothing please help i'm getting angry

    My phone wont let me download anything even free stuff or update.it keep saying something wrong with my billing info so i fix it but still cant download.I signed out sign back in still nothing please help i'm getting angry

    If it says your billing info is wrong that means that your credit card issuer is refusing to approve your account. You will have to solve the problem with your bank or credit card company.

  • What's wrong with my browsers?

    When i first got my macbook the internet was going really slow but then i changed the dns server to 4.2.2.2 and sometimes change it to 4.2.2.1 and the internet got better but now my browsers are acting funny.
    One moment i'm surfing webpages with safari or firefox.... Chatting with AdiumX or MS Messenger... and suddenly it just stops... Msn is getting time-out's, Safari says I'm not connected.
    But Airport sais it is still connected to my wireless network (with all the black bar's filled). It has valid IP adress etc, But everywhere I want to go on the internet it sais I'm not connected.
    When I disconnect the airport en let it reconnect with my wireless network, the connection is fine.
    how can i fix this?

    Most users shouldn't be manually entering DNS addresses, and those DNS addresses you mention probably aren't intended for end users. Is Level3 your ISP?
    That doesn't answer 'what's wrong with my browsers?', but a good start would be to configure your network according to your ISP's instructions. If you have DNS problems then, you might try using OpenDNS.

  • What's wrong with YouTube on Safari!!!

    Hi guys,
    This is just recently!! YouTube on Safari is literally BAD EXPERIENCE!!!
    When I choose to play something, it either:
    - Play the first 4 seconds and repeat with a black screen
    - Play 10-15 seconds as a whole clip instead of the proper lenght of the clip
    - It keeps freezing my browser if a video managed to load, it gets stuck A LOT, it plays only part of it and not all of it and it just doesn't work!!
    What is going on! I tried all of this uninstall Flash and reinstall and/or whatever!!!
    It works smoothly on Firefox, something is wrong with SAFARI!!!
    What can I do? anybody with the same issue and found out a solution!!
    I can!!
    Sul.

    Hi ...
    Quit Safari.
    Really helps to tell us which Mac OS X you have installed when you post.
    If you are running v10.7 Lion, open System Preferences > Flash Player then select the Storage tab. Click: Delete All
    If you aren't running v10.7 Lion, start here:
    If you are sure you UNINSTALLED the original Flash plugin first before reinstalling new, launch Safari From your Safari menu bar click Safari > Empty Cache
    Now try a video.
    BTW... if you have the ClickToFlash extension installed, that can prevent Flash based video from streaming. It can also be installed as a plugin in /Library/Internet-Plug-Ins.
    And check to see if Safari is running in 32 bit mode. Right or control click the Safari icon in your Applications folder then click Get Info. If the box next to:  Open in 32 bit mode  is selected, deselect, quit then relaunch Safari.
    edited by:  cs

Maybe you are looking for