Utilities - Calendar, TimeZone, Date, etc.

Could someone tell me why my code is not returning the correct month and day? When I run the program, I got the month as 5 and the day as 3, when it's actually 6 (June) and 11 (day).
Thanks!
import java.util.*;
import java.text.*;
public class DateTest {
     public DateTest() {
          GregorianCalendar cal = new GregorianCalendar();
          TimeZone tz = TimeZone.getTimeZone("America/New_York_City");
          cal.getInstance(tz, Locale.US);
          String timeZone = tz.getID();
          int month = cal.get(Calendar.MONTH);
          int day = cal.get(Calendar.DAY_OF_WEEK);
          System.out.println(month);
          System.out.println(day);
          System.out.println(timeZone);
          // System.out.println(cal.toString());
          // SimpleDateFormat format = new SimpleDateFormat();
     public static void main( String[] args) {
          new DateTest();
}

It's weird I know, but this is how it goes: Months start at 0. So 0 would be January, 1 Feb, etc. Don't ask me why. The reason why you're getting 3 is because it's the third day of the week. Try changing it to this.
int day = cal.get(Calendar.DAY_OF_MONTH);And that should work. Add one to the month, that's just a terrible idea on their part in my opinion, but that's how it goes.

Similar Messages

  • HT1386 I have an older iPhone (3gs) and need to upgrade to a newer phone (4S).  I need to get my NOTES, CALENDAR, CONTACTS, PICTURES, etc backed up on iTunes so I can get that data loaded onto the new phone.  But not sure how to do that.

    I have an older iPhone (3gs) and need to upgrade to a newer phone (4S).  I need to get my NOTES, CALENDAR, CONTACTS, PICTURES, etc backed up on iTunes so I can get that data loaded onto the new phone.  But not sure how to do that.  When I open iTunes it has a button that say "Back Up iPhone", but I'm not sure what that does.  When I go into the sync options it say I have another user account and asks me if I want to merge of replace. I'm assuming it's trying to tell me I have an older iTunes Library, but don't know that.  Geez, maybe people over 60 shouldn't have iPhones, iTunes just bafles me.

    http://manuals.info.apple.com/en_US/iphone_user_guide.pdf

  • Sync my calendar dates, etc. to phone

    I have a Razr Maxx phone. How do I sync my calendar dates, etc. to my phone?

    Do you mean from GOOGLE Calendar, or some other Calendar (e.g., OUTLOOK) ??  Google Calendar is already available to SYNC .. you just need to make sure the GMAIL account is selected in your Calendar APP (settings)

  • Can anyone tell me how to link my iphone to my computer so that my calendar notebook contact etc are all linked?

    can anyone tell me how to link my iphone to my computer so that my calendar notebook contact etc are all linked?

    Hey randers4 thanks for the info....
    It's all set up already but just dosn't sync.... i think it's to do with the fact that a few day's ago i tried to sort out the fact that the date on my iphone was saying 2557 but on my macbook pro it was 2014 so i thought if i signed out of my icloud on my coputer and then signed back in then it would automaticly all sync but it didn't and the date still stayed the same until i was told what to do by someone on here but now i can't sync my computer and phone up...... and what you just sent me dosn't work.... any other ideas?

  • TimeZone data updates?

    Hi,
    In three weeks, Indiana will begin observing Daylight Savings Time for the first time, and several Indiana counties will be switching from Eastern Time to Central Time (http://en.wikipedia.org/wiki/Daylight_savings_time#Indiana). This change will have an impact on some legacy code in one of my company's applications which uses the java.util.TimeZone class to retrieve a TimeZone based on a zone String passed to the TimeZone.getTimeZone method.
    Is there any patch or other mechanism available that would allow us to update the TimeZone data for our JVM? The version that I'm working with is j2sdk1.4.2_07, but I anticipate that we'll also need to update our 1.5 environments as well. Any help would be greatly appreciated. Thanks,
    Rick

    sorry, i guess i wasn't clear. i meant the timezone data version, such as tzdata2005m, tzdata2005n, etc. or at least the dates, etc. for the data.
    w/the upcoming US DST changes & the recent australian DST monkey business i'd like to know which servers (ie JVM version) are going to be giving me tz heachaches.
    thanks.

  • HT4818 hey, I want to install windows on my mac, I have mac osx lion and I'm soon going to get mountain lion. If I use Boot camp to install windows do I need a windows disc, will i lose all my data, etc. If so how to I save them. Can I switch back to osx

    hey, I want to install windows on my mac, I have mac osx lion and I'm soon going to get mountain lion. If I use Boot camp to install windows do I need a windows disc, will i lose all my data, etc. If so how to I save them. Can I switch back to osx after I install windows. ( can I switch between Windows and OS X as many times as I want.) thanks for answering.
    Sebastian

    hey, I want to install windows on my mac, I have mac osx lion and I'm soon going to get mountain lion. If I use Boot camp to install windows do I need a windows disc, will i lose all my data, etc. If so how to I save them. Can I switch back to osx after I install windows. ( can I switch between Windows and OS X as many times as I want.) thanks for answering.
    Sebastian

  • How can I transfer my contacts, calendar items, notes etc. from one apple-id to another?

    I moved from DK to the US and now I have created a US-apple-ID. How do I transfer all my contacts, calendar items, notes etc. from my DK-apple-ID to my new US-apple-ID?

    Hey kristina rivera!
    You will first want to export your contacts from iCloud using the following article:
    iCloud: Export contact information as a vCard
    http://support.apple.com/kb/PH3606
    You will then want to log in to her iCloud account, then import the vCard file that had been exported from your iCloud account:
    iCloud: Import a vCard
    http://support.apple.com/kb/PH3605
    Take care, and thanks for visiting the Apple Support Communities.
    -Braden

  • Calendar month dates in horizontal line

    Is there anyway to show calendar month dates in horizontal line?
    First line will have dates and then second line will have day i.e Sat, Sun, Mon.......
    1 2 3 4 5 6 7 8 9 ........31

    orion_123 wrote:
    Is there anyway to show calendar month dates in horizontal line?
    First line will have dates and then second line will have day i.e Sat, Sun, Mon.......
    1 2 3 4 5 6 7 8 9 ........31You can do all sorts of things if you put your mind to it... e.g.
    SQL> break on month skip 1
    SQL> set linesize 200
    SQL> set pagesize 2000
    SQL> column month format a20
    SQL> column week format a4
    SQL> with req as (select '&Required_Year_YYYY' as yr from dual)
      2      ,offset as (select case when to_char(trunc(to_date(yr,'YYYY'),'YYYY'),'IW') in ('52','53') then 1 else 0 end as offset from req)
      3  select lpad( Month, 20-(20-length(month))/2 ) month,
      4         '('||week||')' as week, "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"
      5  from (
      6    select to_char(dt,'fmMonth YYYY') month,
      7    case when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 0 then '53'
      8         when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 1 then '54'
      9         when to_char(dt, 'mm') = '01' and to_char(dt,'iw') in ('52','53') then '1'
    10         else to_char(to_number(to_char(dt,'iw'))+offset) end as week,
    11    max(decode(to_char(dt,'d'),'1',lpad(to_char(dt,'fmdd'),2))) "Mo",
    12    max(decode(to_char(dt,'d'),'2',lpad(to_char(dt,'fmdd'),2))) "Tu",
    13    max(decode(to_char(dt,'d'),'3',lpad(to_char(dt,'fmdd'),2))) "We",
    14    max(decode(to_char(dt,'d'),'4',lpad(to_char(dt,'fmdd'),2))) "Th",
    15    max(decode(to_char(dt,'d'),'5',lpad(to_char(dt,'fmdd'),2))) "Fr",
    16    max(decode(to_char(dt,'d'),'6',lpad(to_char(dt,'fmdd'),2))) "Sa",
    17    max(decode(to_char(dt,'d'),'7',lpad(to_char(dt,'fmdd'),2))) "Su"
    18    from ( select trunc(to_date(req.yr,'YYYY'),'y')-1+rownum dt
    19           from all_objects, req
    20           where rownum <= add_months(trunc(to_date(req.yr,'YYYY'),'y'),12) - trunc(to_date(req.yr,'YYYY'),'y') )
    21        ,offset
    22    group by to_char(dt,'fmMonth YYYY'),     case when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 0 then '53'
    23                                                  when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 1 then '54'
    24                                                  when to_char(dt, 'mm') = '01' and to_char(dt,'iw') in ('52','53') then '1'
    25                                                  else to_char(to_number(to_char(dt,'iw'))+offset) end
    26    ) x
    27  order by to_date( month, 'Month YYYY' ), to_number(x.week)
    28  /
    Enter value for required_year_yyyy: 2012
    old   1: with req as (select '&Required_Year_YYYY' as yr from dual)
    new   1: with req as (select '2012' as yr from dual)
    MONTH                WEEK Mo Tu We Th Fr Sa Su
        January 2012     (1)                     1
                         (2)   2  3  4  5  6  7  8
                         (3)   9 10 11 12 13 14 15
                         (4)  16 17 18 19 20 21 22
                         (5)  23 24 25 26 27 28 29
                         (6)  30 31
       February 2012     (6)         1  2  3  4  5
                         (7)   6  7  8  9 10 11 12
                         (8)  13 14 15 16 17 18 19
                         (9)  20 21 22 23 24 25 26
                         (10) 27 28 29
         March 2012      (10)           1  2  3  4
                         (11)  5  6  7  8  9 10 11
                         (12) 12 13 14 15 16 17 18
                         (13) 19 20 21 22 23 24 25
                         (14) 26 27 28 29 30 31
         April 2012      (14)                    1
                         (15)  2  3  4  5  6  7  8
                         (16)  9 10 11 12 13 14 15
                         (17) 16 17 18 19 20 21 22
                         (18) 23 24 25 26 27 28 29
                         (19) 30
          May 2012       (19)     1  2  3  4  5  6
                         (20)  7  8  9 10 11 12 13
                         (21) 14 15 16 17 18 19 20
                         (22) 21 22 23 24 25 26 27
                         (23) 28 29 30 31
         June 2012       (23)              1  2  3
                         (24)  4  5  6  7  8  9 10
                         (25) 11 12 13 14 15 16 17
                         (26) 18 19 20 21 22 23 24
                         (27) 25 26 27 28 29 30
         July 2012       (27)                    1
                         (28)  2  3  4  5  6  7  8
                         (29)  9 10 11 12 13 14 15
                         (30) 16 17 18 19 20 21 22
                         (31) 23 24 25 26 27 28 29
                         (32) 30 31
        August 2012      (32)        1  2  3  4  5
                         (33)  6  7  8  9 10 11 12
                         (34) 13 14 15 16 17 18 19
                         (35) 20 21 22 23 24 25 26
                         (36) 27 28 29 30 31
       September 2012    (36)                 1  2
                         (37)  3  4  5  6  7  8  9
                         (38) 10 11 12 13 14 15 16
                         (39) 17 18 19 20 21 22 23
                         (40) 24 25 26 27 28 29 30
        October 2012     (41)  1  2  3  4  5  6  7
                         (42)  8  9 10 11 12 13 14
                         (43) 15 16 17 18 19 20 21
                         (44) 22 23 24 25 26 27 28
                         (45) 29 30 31
       November 2012     (45)           1  2  3  4
                         (46)  5  6  7  8  9 10 11
                         (47) 12 13 14 15 16 17 18
                         (48) 19 20 21 22 23 24 25
                         (49) 26 27 28 29 30
       December 2012     (49)                 1  2
                         (50)  3  4  5  6  7  8  9
                         (51) 10 11 12 13 14 15 16
                         (52) 17 18 19 20 21 22 23
                         (53) 24 25 26 27 28 29 30
                         (54) 31
    64 rows selected.
    SQL>That's just an example, but yes, of course you can do it. Oracle provides excellent DATE functionality.

  • I want to upgrade my phone to the 4 or 4s.  My macs are still running Tiger.  If I bought an iPad 2, could I sync everything to it from the 4 without using a Mac at all, and then be able to iCloud my calendar and contacts, etc?

    I want to upgrade my phone to the 4 or 4s.  My macs are still running Tiger.  If I bought an iPad 2, could I sync everything to it from the 4 without using a Mac at all, and then be able to iCloud my calendar and contacts, etc?

    Radiation Mac wrote:
    And you must be using a recent version of iTunes on your iMac in order to activate the iPad,  So, no.
    You don't need a computer to activate a new iOS device anymore. Anything with iOS 5 can be activated over a WiFi network (or cellular if that applies).

  • Calendar Tile on Windows 8.1 displaying incorrect date for icloud calendar but date icon displays correct date on iPhone 5 and iPad Air

    Calendar Tile on Windows 8.1 displaying incorrect date for icloud calendar but date icon displays correct date on iPhone 5 and iPad Air.  Date on Windows 8.1 is correct.  Thank you.

    Try doing  a reset on your phone. Sounds like your carrier's time set is not getting through to your device. If the reset doesn't do it, then go to Settings>General>Reset>Reset Network Settings. That should do it.

  • Just bought a used MacBook pro after my previous died. I want to migrate my applications, data, etc from a time machine backup of the old computer to the new. Will this affect, or overwrite the Apps., data, etc existing on the new machine?

    Just bought a used MacBook pro after my previous died. I want to migrate my applications, data, etc from a time machine backup of the old computer to the new. Will this affect, or overwrite the Apps., data, etc existing on the new machine?

    No. Only those Apps that are not installed on the new will migrate over.

  • My emails in mail have just disappeared leaving the headers of date etc

    my emails in mail have just disappeared leaving the headers of date etc
    any one out there who has had this before
    smburc

    Quit Mail. Force quit if necessary.
    Back up all data. That means you know you can restore the Mail database, no matter what happens.
    Triple-click anywhere in the line below on this page to select it:
    ~/Library/Mail/V2/MailData
    Copy the selected text to the Clipboard by pressing the key combination command-C. In the Finder, select
    Go ▹ Go to Folder
    from the menu bar. Paste into the box that opens (command-V), then press return.
    A folder window will open. Inside it there should be files with names as follows:
    Envelope Index
    ExternalUpdates.storedata
    Move those files to the Desktop, leaving the window open. Other files in the folder may have longer names that begin as above. Move those files, if any, to the Trash.
    Log out and log back in. Relaunch Mail. It should prompt you to re-import your messages. You may get a warning that the index is damaged and that Mail has to quit. Click OK. Warning: The process may take hours if you have gigantic mailboxes. For reasonable-sized mailboxes, it should only take a few minutes.
    Test. If Mail now works as expected, you can delete the files you moved to the Desktop. Otherwise, post your results.

  • BAPI or FM for geting  all sales master data, header data , item data etc

    Hi experts,
          In my requirement  i need a BAPI  (or) Function module for getting all "Sales information" data means header data , item
    data, scheduled data  etc    .
    Thank you,
    Dinesh Reddy.

    Hi,
    check BAPI_SALESORDER_GETLIST
    I hope it helps you....
    Regards,
    NaPPy

  • I 'm a novice..if i downloaded a free siriusxm radio app for ipod touch,are there any charges i.e. data etc.?

    i'm a novice..if i downloaded a free siriusxm radio app for ipod touch,are there any charges i.e. data etc.? or is it free

    You have to have the special SiriusXM account for listening and you must have a regular SiriusXM subscription. Cost is around $15.00 per month. The Live365 app only requires a $7.95 per month subscription and provides much more than SiriusXM.

  • My Question On Calendar and Date

    Hi, I am making a query to a table: T_HR_CONTRACT,
    which stores the labor contract of a company.
    END_DATE is a field of table T_HR_CONTRACT. Its type is date.
    Now, I need to search the contract end in each month.
    select * from T_HR_CONTRACT where fEND_DATE >= theStartDayOfCurrenctMonth and fEND_DATE < theStartDayOfNextMonth;
    or
    select * from T_HR_CONTRACT where fEND_DATE >= theStartDayOfCurrenctMonth and fEND_DATE <= theLastDayOfCurrenctMonth;
    How can I utilize the java class Calendar or Date to get
    the first day of current month,
    the last day of current month,
    the first day of next month?
    I am new to Calendar and Date class. Please give me some help!

    Ok, I have solve the problem as following:
    //get the first day of this month, by using StringBuffer, we can enhance
    //the effiency
    StringBuffer today = new StringBuffer();
    Calendar rightNow = Calendar.getInstance();
    today.append(rightNow.get(rightNow.YEAR));
    today.append("-");
    today.append((rightNow.get(rightNow.MONTH) + 1));
    today.append("-01");
    String todayDate = today.toString();
    //get the first day of next month
    StringBuffer next = new StringBuffer();
    //if the month is December, then get the first day of next year!
    if(rightNow.get(rightNow.MONTH) == 11)
    next.append(rightNow.get(rightNow.YEAR) + 1);
    next.append("-01-01");
    else
    next.append(rightNow.get(rightNow.YEAR));
    next.append("-");
    next.append(rightNow.get(rightNow.MONTH) + 2);
    next.append("-01");
    String nextDate = next.toString();

Maybe you are looking for

  • Needs Clarification in AME

    Hi all, I am facing the following scenario in my project. Rule 1: Approver Group:A condition 1:amount : >10000 < 20000 condition 2:percentage : >5 <10 condition 3:country : any (normally this condition is no need to set) Rule 2: Approver Group : B co

  • Getting exit code 7 when trying to install elements 11

    Hi im just wondering why im getting this error when trying to install on my mac book? Exit Code: 7 -------------------------------------- Summary -------------------------------------- - 0 fatal error(s), 22 error(s), 2 warning(s) ----------- Payload

  • New OBI/BI Apps installation for PS 9.1 Financials. 7.9.6.3 or 7.9.6.4?

    Hi Folks, We're starting a green field implementation of OBIEE 11g with BI Apps. We want to integrate with PeopleSoft 9.1 Financials. I see 7.9.6.4 was release recently, and now we're undecided on whether to go with 7.9.6.3 or 7.9.6.4. The one piece

  • New External Hard Drive, Afraid to Sync my Ipod

    Hi, I moved my music files to an external hard drive, now that I have a problem is when I start researching how it should have been done... And it looks like I did it wrong. I moved all of my files, and itunes library to the EHD with no problem, but

  • How to download FDM Adapter for Essbase in the latest version 11.1.2.2

    Hi all, I can't find the download package for FDM Adapters in the version 11.1.2.2.0 (edelivery, Windows x64), how can I download and install them? Thanks.