Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

parsing time periods params

Thread view: 
Pawel - 24 Apr 2006 13:53 GMT
Hallo
Do You know any ready to use class/method that would return number of seconds, something like that:
method( "2" ) : would return 2 [secs]
method( "2s" ) : would return 2 [secs]
method( "2m" ) :  would return 120 [secs]
method( "2h" ) : would return 7200 [secs]
method( "2d" ) : ...

Greetings
Chris Diver - 24 Apr 2006 14:49 GMT
> Hallo
> Do You know any ready to use class/method that would return number of seconds, something like that:
[quoted text clipped - 5 lines]
>
> Greetings
Hi,

You could write it yourself, fairly simply. I'm not sure
of any ready to use methods.

time = "";
if( time contains an d ){
    return the number bit multiplied by 86400;
}
else if( time contains a h ){
    return the number bit x 3600;
else if( time contains a m ){
    return the number bit x 60;
}
else{
    return the number bit;
}

This could be of use.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

Chris
PMA - 24 Apr 2006 14:52 GMT
Pawel a écrit :

> Hallo
> Do You know any ready to use class/method that would return number of seconds, something like that:
[quoted text clipped - 5 lines]
>
> Greetings

Your pb seems very simple :
a) either you have very simple inputs such as above you just split your
input String into two parts (the numeric & the unit) then do the
calculous by yourself
b) either it ca be more sophisticated, just use a RegExp

Philippe
Pawel - 25 Apr 2006 09:31 GMT
> ting-Date: Mon, 24 Apr 2006 13:53:05 +0000 (UTC)
> User-Agent: G2/0.2
[quoted text clipped - 21 lines]
> calculous by yourself
> b) either it ca be more sophisticated, just use a RegExp
Philippe and Chris
Thank You for Your suggestions.
I do not like reinventing the wheel. It is so simple and ubiquitous thing that I just thought that there might be some jdk classes for that.
Greetings


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.