[Show all top banners]

CrystalCracker
Replies to this thread:

More by CrystalCracker
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 Java Experts: Help Needed
[VIEWED 2626 TIMES]
SAVE! for ease of future access.
Posted on 05-19-07 6:19 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I am trying to prevent the time user provides is not a time in the past.

String userDate= request. getParameter("date);//yyyy-mm-dd
String userTime= request.getParameter("time);//hh:mm (24 hour notation)
DateFormat df= new SimpleDateFormat("yyyy-dd-mm hh:mm");
Date userDateTime=df.parse(userDate+ " " + userTime);

Date serverTime= new Date();
if(serverTime.after(userDateTime){
return false;
}

This works well. But now I have to consider the user's time zone, and this is where I hesitate.
The time zone user provides is in the format +7:30, -5 , 0 etc format from UTC.
Is there any simple way to accomodate the time zone?
or else I have to convert the user timezone input from +7:30 to 0700, which is the DateFormat requires in java for time zone. I dont want to do a lot of parsing. But is it the only way to do it? How are you guys been doing it?
 
Posted on 05-19-07 6:40 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

FROM SOURCE http://www.exampledepot.com/egs/java.util/GetTimeOtherZone2.html




// Given a local time of 10am, get the time in Japan
// Create a Calendar object with the local time zone
Calendar local = new GregorianCalendar();
local.set(Calendar.HOUR_OF_DAY, 10); // 0..23
local.set(Calendar.MINUTE, 0);
local.set(Calendar.SECOND, 0);

// Create an instance using Japan's time zone and set it with the local UTC
Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan"));
japanCal.setTimeInMillis(local.getTimeInMillis());

// Get the foreign time
int hour = japanCal.get(Calendar.HOUR); // 3
int minutes = japanCal.get(Calendar.MINUTE); // 0
int seconds = japanCal.get(Calendar.SECOND); // 0
boolean am = japanCal.get(Calendar.AM_PM) == Calendar.AM; //true


// Given a time of 10am in Japan, get the local time
japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan"));
japanCal.set(Calendar.HOUR_OF_DAY, 10); // 0..23
japanCal.set(Calendar.MINUTE, 0);
japanCal.set(Calendar.SECOND, 0);

// Create a Calendar object with the local time zone and set
// the UTC from japanCal
local = new GregorianCalendar();
local.setTimeInMillis(japanCal.getTimeInMillis());

// Get the time in the local time zone
hour = local.get(Calendar.HOUR); // 5
minutes = local.get(Calendar.MINUTE); // 0
seconds = local.get(Calendar.SECOND); // 0
am = local.get(Calendar.AM_PM) == Calendar.AM; // false
 
Posted on 05-19-07 6:46 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Thanks thapap,
I actually dont know the time zone place, I only know the offset. So I cant use getTimeZone("Japan");
I have the offset string, and I want to convert it to a timezone. Thats my problem in short. I can do it by parsing the string, and that can be error-prone depending on the user input.
 
Posted on 05-21-07 4:57 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

you can use

You can use the getAvailableIDs method to iterate through all the supported time zone IDs. You can then choose a supported ID to get a TimeZone. If the time zone you want is not represented by one of the supported IDs, then a custom time zone ID can be specified to produce a TimeZone. The syntax of a custom time zone ID is:

CustomID:
GMT Sign Hours : Minutes
GMT Sign Hours Minutes
GMT Sign Hours
Sign: one of
+ -
Hours:
Digit
Digit Digit
Minutes:
Digit Digit
Digit: one of
0 1 2 3 4 5 6 7 8 9


Hours must be between 0 to 23 and Minutes must be between 00 to 59. For example, "GMT+10" and "GMT+0010" mean ten hours and ten minutes ahead of GMT, respectively.

read more here http://java.sun.com/j2se/1.4.2/docs/api/java/util/TimeZone.html
 
Posted on 05-21-07 8:39 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Thanks. I got it working.
 
Posted on 05-21-07 9:25 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 
 
Posted on 05-21-07 9:33 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Ha ha... Revenge??
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 365 days
Recommended Popular Threads Controvertial Threads
Lets play Antakshari...........
शीर्षक जे पनि हुन सक्छ।
NRN card pros and cons?
What are your first memories of when Nepal Television Began?
TPS Re-registration
TPS Re-registration case still pending ..
Democrats are so sure Trump will win
is Rato Bangala school cheating?
What Happened to Dual Citizenship Bill
Basnet or Basnyat ??
nrn citizenship
H1B fraud
इन्दिरा जोशीको चिन्ता लौच
Sajha has turned into MAGATs nest
Nas and The Bokas: Coming to a Night Club near you
श्राद्द
सेक्सी कविता - पार्ट २
डलराँ कमाएर ने .रु मा उडांउदा !@#
ChatSansar.com Naya Nepal Chat
Why always Miss Nepal winner is Newari??
Nas and The Bokas: Coming to a Night Club near you
Mr. Dipak Gyawali-ji Talk is Cheap. US sends $ 200 million to Nepal every year.
Harvard Nepali Students Association Blame Israel for hamas terrorist attacks
TPS Update : Jajarkot earthquake
is Rato Bangala school cheating?
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters