Confused with Calendars and TimeZones

Hi, I'll explain what I want to do. I have a table with several of what I call a "Time Ranges". Each Time Range has a day (day of week), beginTime and endTime. I also have different clients, each from a different country. Each client has a timezone associated (the format of this timezone is not defined just yet, but it should be something like -3, -4, +1, etc).
I want to get the current date, and be able to figure out if it is within a certain time range. For example, right now in Argentina is
11:48 AM GMT-3
This should match these time ranges:
11:00~12:00 | -3
10:00~11:00 | -4
13:00~14:00 | -1
And should not match this time range:
11:00~12:00 | -4
I'm trying to get the "current time for a certain time zone" with Calendar, and then be able to extract the time from that Calendar and compare it with my beginTime and endTime. I'm not getting anywhere.
Something like this:
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT-08:00"));
System.out.println(cal.getTime());Is printing GMT-3 time. Please help.

manugarciac wrote:
Ok, I did it like this. The TimeRange Class has this method:
public boolean isActive(String timezone) {
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timezone));
if (cal.get(Calendar.DAY_OF_WEEK) == this.day) {
Time time = new Time(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), 0);
return (beginTime == null || time.after(beginTime)) && (endTime == null || time.before(endTime));
return false;
}Timezone should come in this format: "GMT-04:00" and Time is java.sql.Time.
The only downside is that the Time constructor I used is deprecated. It says I should use the one that uses milliseconds since 1970. That kinda sucks, as I don't really care how much time passed since that time for this time. Any ideas of what I should use?forget java.sql.Time. use Calendar.set(int year, int month, int date, int hourOfDay, int minute) to set beginTime and endTime. use Calendar.compareTo(Calendar anotherCalendar) for the test.
Edited by: pete_d on Sep 10, 2010 3:09 PM
Not sure exactly what's going on in your TimeRange class but if the hour, minute, second and time zone in addition to the day of week (it seems that it does) for both begin and end time, then you can use this to create a Calendar instance to compare with the current time or to whatever other Calendar instance you want to check using its year, month day.

Similar Messages

  • Ipad Calendar and Timezones

    I use mobile me on the waeb, my mac, iphone and ipad.
    I would like the ipad to be my "number 1" calendar so that I can keep it always open, but it is very erratic:
    1. Timezones- If I edit an appointment on the ipad after it has been input or synced I no longer have access to the timezone.
    2. The same goes for Calendar (Can't change from one calendar to another after appointment has bben nput or synched)
    3. Synching is erratic at best. events synch, don't synch or get doubled depending on how the wind is blowing. I tried all combinations with mobile me, mac, iphone and ipad and could not find a pattern.

    Thanks for all the help, but where do I swipe and delete?
    I tried that inside the calendar app, on the iPad and birthday calendar...but all it does is selects the calendar, and no delete button appears.

  • Problem with Calendar and drag and drop a name to a Time spot with palm desktop. Full name does not appear only last name.

    Im having a problem with the palm desktop. When in “Contacts” and I list (LastName,First name) and then I move to the Calendar and drag and drop a name to a Time spot Only the LAST name of the Person appears. How can I fix this so that I can see there full name ?
    Also when If list (Company,Last Name) then go to calendar Some of my contacts are out of order but if I drag and drop them into the calendar day the full name appears. Is there any why of fixing this ? Or having it work properly ?
    Im running  XP pro
    Palm Desktop Version 4.1.4
    Post relates to: Treo 680 (Rogers)
    Message Edited by corrado on 07-21-2008 08:55 AM

    Any Idea how to fix the problem that I am getting when using the (Company,Last Name) and the contacts being out of order in the calander ? I have some last names starting with A then it goes to D then a B then a stack more A and none of then have a Company field filled out in them in them...
    Thanks for looking into that for me but it seems really stange to offer the option but not put in the first name in the calander when you drage the name over. I hope this is fixed in the future. Can anyony sugest another desktop platform I can use if I cant fix my problem with the   (Company,Last Name) problem?
    Post relates to: Treo 680 (Rogers)

  • IPhone - Sync issue with Calendar and Outlook 2003

    I have been syncing with no problem up to yesterday - now I can't sync my Calendar with my PC. It doesn't make any difference whether I make an entry in iPhone or Outlook. I have reset sync history in iTunes - no change.
    The only thing that I can think of that I did out of the ordinary was to copy and paste my contacts into another contacts group in Outlook.
    It would appear to be a problem with Outlook as the iPhone syncs with iCal and Address book on my G4 laptop.
    Appreciate your help.
    Alani

    Outlook is definately a problem. Ive been at it for a couple of days going through this thread and others. Still not syncing.
    What Apple has to realize is that windows people have different microsoft offices, i use 2000 because the schedule is shared between everyone, this is an addon in newer copys of office.
    When i make a call or recieve a call i would like to see an option to add the caller to the schedule .. When your on the phone with the caller you can just hit a button and it brings you right to the calendar and enters the caller in the schedule where ever you place them.
    Anyway i will keep at the sync thing for a while and see what happens. Nothing so far. l8r

  • Calendar and timezones

    i'm not sure if it's just me not quite using my phone properly, but i've had a couple of problems with the calendar feature on my 6280. the first time i noticed it was when i put one particular appointment into the calendar - i was in the uk at the time, but the appointment was in france. now, when i arrived in france the clock updated itself as normal to french time, but also moved the apointment forward in the calendar by one hour. i.e. it assumed that because i was using gmt when i made the appointment, that the appointment was gmt and duly compensated. i thought this was a bit strange.
    however, next thing i know, just this week with the changing of the clocks to summer time, i found that once again, when the clocks change, all my appointmens were moved forward an hour. surely, when you put an appoinment into the calendar, you don't have to work out which time zone it is in or whether it's on summer or winter time or whatever. when you make an appointment you say, for example, 9 o'clock and you put in 9 o'clock into the calendar and that's it. you don't think, for example, 'ok the appointment is 9 o'clock in france, but that's 8am gmt. oh, but wait, the clocks change so i need to add and extra hour...' surely this is really badly thought out by whoever produced the sofware. i'm sure i can't be the only person in the world to have appointments in two different time zones...
    can anyone help? or at least tell me that it's badly thought out and that i'm not missing the point somewhere.
    thanks

    I find that the best thing to do is this:
    When you get a new phone, switch off the auto-update feature. It isn't worth the trouble.
    Next, set the correct time zone (currently GMT+1 in the UK or GMT+2 in France).
    Then set the time, and never touch it again.
    When you move between time zones, or change from summer to winter time, always change the time zone rather than the time.
    Chris
    6230i (the last bug-free Nokia?)
    Vodafone UK contract since 1992

  • Trouble with calendar and events populating phone

    I am having a significant amount of trouble with getting my phone to populate my calendar and my events.  I have had trouble with this since I got my phone at the end of April and I am getting tired of it.  If i put new calendar entries in on my local calender or I sync from my active sync calender, the result is the same - nothing will show.  The strange thing is is that the reminders will open up, everything is invisible to me.  I've reinstalled the software and have been through the settings on my calender accounts.  I am a business person and this is very important to me and I am starting to get frustrated with this. 
    Any help would be greatly appreciated!

    Ok, I finally figured it out or better I finally got it to work after playing with it. For those who have the same issues I will give you the steps I have taken. It might sound a bit senseless but I didn't know what I was doing might actually make it work.
    Anyways, I read somewhere that in order to be able to set a default Calendar in Settings they added a CalDAV account. I didn't have one but I do have a gmail account. Before adding that I tried again turning on and off the iCloud calendar which didn't help.
    Then I went to the ical app on the iphone and added a new calendar which I called the same as my main one on the iCloud site (HomeCloud). I rebooted the phone every time I made a change. But didn't help either.
    Then I deleted my iCloud account on the iphone reboooted and added it again, rebooted. Now the "Calendars" calendar was not on the iphone anymore but I could see my main HomeCloud, my UK Holiday and the gmail account calendar but nothing was synced.
    Last step I tethered the iphone to my imac and synced via iTunes again and voila I could see everything synced correctly. Last thing I had to uncheck the gmail calendar on the iphone because it was set as the default and now the events I put in the iphone sync correctly with the iCloud site and my icals on my machines.
    I hope this will help whoever has the same issue.

  • TA44535 ipod touch with calendar and contacts?

    Why can't I have a calendar and contacts in my Ipod Nano? I need it! I think many peoples need it!
    Because its very practical,  you have in a clock (ipod nano) with "time maneger".
    Will have this up grade in the future?

    You aren't speaking to Apple here.  If you have suggestions to make regarding their iPod Nano, use the forum on this page.
    http://www.apple.com/feedback/ipodnano.html
    It's likely they aren't included due to the 6G Nano's small screen real estate.
    B-rock

  • Performance issue with calendar and applescript

    Hi Community,
    I have a performance issue using applescript and calendar with this script:
    tell application "Calendar"
              tell calendar "Cal"
                                            set theList to (get {summary, start date, end date, uid} of events)
    end tell
    end tell
    There are app. 700 events in the calendar "Cal". Therefore the get-command takes about 15 seconds. The problem is, that iCal is completely blocked for this time. This means it is even not possilbe to scroll through the calendar. This problem occurs only under OS X 10.9. With OS X 10.8.x it is still possible to use calendar even a time-consuming get-command is processed.
    Any ideas? Maybe there is a way to reduce the task-priority of an applescript?

    I have to step in here...
    1) Must I set "None" or "On Time"
    - In order for the Calendar to fire an Alarm, it must know what time to fire the alarm. In the event of an All Day Event, it will go off at 12am. The option for "Repeat", below the "Alarm", states the frequency of the event (Daily, Weekly, Monthly, Yearly, etc). So to set an alarm that fires once a month, set the TIME you want the alarm to go off (Make sure "All Day" is unchecked if you want a specific time), then choose "On Time" for the "Alarm", and one of the several "Monthly" options for "Repeat". If I missed something in what you were asking, please let me know and I will do my best to more directly answer your question.
    2) Calendar cannot sync with the Mac.
    - Not directly. However, your phone automatically syncs with your Google Calendar, set up if you create your account. If you so choose, you may export your iCal calendar, import it into your Google calendar, and then use your Google calendar (http://calendar.google.com) to manage your agenda. The changes sync automatically with your device.
    Once again, I hope this shed some light on things. To the Verizon rep who originally answered this question: I have no intention to bash you, however please bear in mind that your opinions and comments will always be held in higher regard than mine, so if you choose to answer a question, please try to solve the problem as opposed to just answer the question. I have experience with all manner of devices and operating systems, from WebOS to BB to iOS to Android, and I believe this phone has the best hardware coupled with a solid operating system in TouchWiz, and I don't want to see people frustrated with these devices by questions that get nothing more than, "You can't do that" answers from the people that are expected to support them.

  • Confused with float and double

    Hi,
    I have done the following program which is supposed to deal with temperature and scales.
    import java.math.BigDecimal;
    public class Temperature {
         private float temp;
         private char scale;
         public static void main(String args[]) {
              Temperature t = new Temperature(40.5, 'F');
              System.out.println(t.getCTemperature());
         public Temperature() {
              temp = 0;
              scale = 'C';
         public Temperature(float pTemp) {
              temp = pTemp;
              scale = 'C';
         public Temperature(char pScale) {
              temp = 0;
              scale = 'C';
         public Temperature(float pTemp, char pScale) {
              temp = pTemp;
              scale = pScale;
         public float getCTemperature() {
              if (scale == 'C') {
                   return temp;
              } else {
                   float celciusTemp = 5 * (temp - 32) / 9;
                   BigDecimal bd = new BigDecimal(celciusTemp);
                   return bd.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
    }When I try to compile I get the following error :
    F:\programs\ch4>javac Temperature.java
    Temperature.java:8: cannot find symbol
    symbol  : constructor Temperature(double,char)
    location: class Temperature
    Temperature t = new Temperature(40.5, 'F');
    *^*
    *1 error*
    I don't understand why the number 40.5 is considered like a double and that I can't use Temperature(float, char);
    If I'm not mistaken the compiler is asking for a constructor like Temperature(double, char) right ??
    thanks.

    Can I second Mr TuringPest, and Sir J.Bloch... Do NOT use floats, unless of course you have a really really good reason. Internally, java does all it's floating point arithmetic in doubles anyways, so you're just shooting yourself in the accuracy-foot by forcing it to: promote to double to calculate, "narrow" result back to float... promote, narrow ... promote, narrow ... promote, narrow ... The net result can be astoundingly inaccurate... So just use doubles.

  • I want the example code for Calendar() and TimeZone() in java

    Hi,
    I want the example code for the TimeZone() and Calendar() class in java
    because i new to java, i am not able to understand the concepts properly.
    Thanks...

    Hi Paolo Dema.
    What are the exact spefications of your computer?
    Also did you computer come with 10.6 ot 10.5?.
    You may try entering the MPN (marketing part number) Format: M*****/**
    The MPN can be found on the product packaging or the System Profiler.

  • Outlook 2011 for mac no longer syncs with calendar and contacts

    Hi all,
    Not sure whether the recent security update botched up my sync, but after recently upgrading to MS Office with Outlook 2011 for the Mac, my contacts and calendar items no longer sync.  I've applied the revised security patch to no avail.  In fact, I noticed that my contacts were no longer syncing prior to the security update, and in the last day or so, I have noticed that calendar items have ceased to sync.  I've tried all of the Microsoft and Apple knowledge-based recipes to correct the problem, but it persists.  I may be missing something, or performed the steps out of sequence, but I've tried them many times and I'm sure at least once was to the letter.
    The oddity is that the problem appears to be a broken link between iCal and Outlook via the sync process, which uses MobileMe and is administered through iTunes.  Perhaps someone has a straightforward instruction set to fix that link?
    Is anyone else having this problem of late?  I am on Snow Leopard, 10.6.8 on a 2011 MBP with MS Office 2011 and SP1 installed.
    Thanks much in advance for any helpful advice.

    Thanks Julian for the suggestion. Unfortunately all still checked out and nothing amiss. However, after reinstalling OS 10.6.8 it appears that my calendar items are syncing once again, but not my contacts. I appreciate the suggestion none the less.
    This same thing seems to happen each time I've upgraded Office with the associated version of Entourage, and now Outlook. Ah, well..nothing's ever simple. But I am thoroughly enjoying Outlook and the rest of the Office suite.

  • Problem with date and timezone

    Hello,
    I am encountering a problem with the command new java.util.date() on a hpux 11 machine.
    The "date" from command line returns:
    Tue Oct 26 18:02:02 MEST 2004
    And the date from java returns:
    Tue Oct 26 17:02:02 GMT+01:00 2004
    It is as if the JVM was running on another timezone than the machine. The only change we made is an upgrade from java 1.2.2.04 to 1.2.2.17. Our old java program running since 2000 hasn't changed nor the others environment files.
    Does anyone has an explaination? Javadoc for jav.util.date does not speaks of timezone.
    Thanks in advance,
    Valere

    I have tried, it is the same pb with java 1.4.
    How to set the default timezone for a JVM?
    Concerning the patch, we have several others worksations running well with 1.2.2.04 (except a small display bug that i wanted to correct by upgrading the JVM). To my knowledge, this patch is not installed on any of them.
    Another way to investigate, it seems that the java version installed on the others stations refers to java 3D. What is it? It has a different architecture than standard jre, but java -version seems exactly the same (except the version number itself).
    Mayday, mayday!

  • Totally confused with iCloud and multiple devices

    Ok, So we have two each of the iPods, iPads and now iPhones.  Do we all share the same iCloud? Can we share apps through the cloud? How do I switch my iPad to the new one I got to give this one to my son. I am so new to all this apple stuff. Only been a few months and I'm still really confused.  What all goes to the iCloud? How do we see what's in the iCloud?  I really the the idiots instructions I think to figure this all out?  Can anyone help me?  How can I print from the iPad?  Everything I see says iOS 10 something?  I believe I only have 6 something? 

    Do we all share the same iCloud?
    icloud is designed so that only one user uses it to keep his/her devices in sync.  When multiple users use the same icloud account, they will then be sharing the same email address, contacts, calendars, notes, etc.  Usually that is not what two people want to do.
    Can we share apps through the cloud?
    You buy apps from the itunes store, that's different than icloud, and multiple users can use the same itunes account so that they can share apps, music, etc.  For a family, everyone usually uses the same Apple ID for an itunes account and individual Apple IDs for their icloud accounts.
    How do I switch my iPad to the new one I got to give this one to my son.
    What do you mean by "switch.. ipad to the new one"?
    What all goes to the iCloud?
    Backups of iOS devices, Apple services that you turn on to share data (settings>icloud; on an iOS device), third party apps that use icloud to sync their data between devices, email, photo stream, and more.
    How do we see what's in the iCloud? 
    Icloud is designed primarily for syncing data between the devices of the user - like getting all computers and devices to have the same contacts or calendars.  When you set up syncing (settings>icloud, turn on the services you want synced between your devices), some of that data will also be available to a computer's browser when you log into icloud.com.  Otherwise you view the data using the associated app, like the Calendar app to see events.  Other things that may be on icloud, like backups cannot be seen.  Also iCloud does not provide a photo gallary that others can view in a browser.
    How can I print from the iPad? 
    For that you need an "airprint" compatible printer. See,
    http://support.apple.com/kb/ht4356
    You can also print to a printer that's connected to a computer, but that computer needs special software, like Printopia for macs.
    Everything I see says iOS 10 something?  I believe I only have 6 something?
    There is no "10", version 6 is the current one.  You are probably thinking of OSX, whose versions are 10.x.y.  That's for macs, not iOS devices.

  • I can no longer sync my new Iphone 5 S with Calendar and Contacts on Microsoft Outlook 7 like I did on my I phone 4

    I was able to sync on my I phone 4 with Microsoft Outlook 2007 but have upgraded my phone to I phone 5 S and now I cloud is interferring and i cannot figure out how to get my contacts and calendar to my I phone 5 S from outlook --  any help please????

    Hi S25wankum,
    Welcome to the Support Communities!
    It sounds like you may need to update the iCloud Control Panel software on your Windows computer.
    iCloud Control Panel 3.0 for Windows
    http://support.apple.com/kb/dl1455
    * Note: If you are upgrading from iCloud Control Panel 1.1 or earlier, you will need to sign out of iCloud Control Panel and uninstall it before downloading iCloud Control Panel 3.0
    Note: To create an iCloud account you need an iPhone, iPad, or iPod touch with iOS 5 or later, or a Mac with OS X Lion v10.7.5 or later. Microsoft Outlook 2007 or later or an up-to-date browser is required for accessing email, contacts, and calendars.
    Here is some additional information to help you get started with your iPhone 5S:
    Apple - iPhone 5s - Tips and Tricks
    http://www.apple.com/iphone-5s/tips/
    I hope this helps ...
    - Judy

  • Outlook 2007 Sync Issues with Calendar and Contacts

    I have an original iPhone and since the last iTunes update I can no longer sync my Contacts and Calendar in Outlook 2007 with my iPhone. The separate calendars are no longer showing in iTunes as a sync option only the sync all is available. When I plug in my iPhone to sync it will set in the syncing status for one to two hours and has not finished syncing since this update. I have reinstalled Outlook 2007, I uninstalled and re-installed iTunes, I have reset the sync history and any other fixes I have been able to find on the discussion boards. Does anyone know of a resolution to this problem?

    I'm having similar problems with both yahoo and google on both my and my wife's Pre 2s. Yahoo calendar sync seemed to be working fine a few weeks ago but now absolutely refuses to do anything on my wife's phone (won't even seem to delete the account properly) and only shows a few things on mine. I've tried with different accounts, removing them, deleting the permissions on the yahoo website, the aeroplane mode trick, and restarting the phone. But the same problem. Phone just says it's syncing for long periods of time but then shows nothing for it. I must have removed and added accounts about 30 times in the last 2 weeks.
    Google not syncing back from phone to cloud at all.
    This is pretty annoying - I had better functionality on my old treo 650!
    Anyone have any answers?

Maybe you are looking for