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