Character separator for time hh:mm:ss

D

dougnickerson

There is a DataFormatSymbols class available to get sevaral characters
used to form dates.
The separator used for hours minuts and seconds used for most locales
appears to be ':' In Italy it is '.'
- Ideally it would be neat if there were a method
TimeFormatSymbols::getTimeSeparatorChar() ?

Doug Nickerson
 
R

Roedy Green

There is a DataFormatSymbols class available to get sevaral characters
used to form dates.
The separator used for hours minuts and seconds used for most locales
appears to be ':' In Italy it is '.'
- Ideally it would be neat if there were a method
TimeFormatSymbols::getTimeSeparatorChar() ?

you could format the timestamp 1970 Jan 1 0:00 with the given local
and then use charAt to fish out the interesting characters. But you
never need them. You can simply format with SimpleDateFormat.
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Danish studies of 10,000 birds killed revealed that almost all died in
collisions with buildings, cars and wires; only 10 were killed by windmills.
Alternative energy sources are absolutely necessary.
Global warming will kill birds and bats, as well as other species,
in much greater numbers than wind power."
~ Dr. David Suzuki
 
D

dougnickerson

you could format the timestamp 1970 Jan 1 0:00 with the given local
and then use charAt to fish out the interesting characters.  But you
never need them.  You can simply format with SimpleDateFormat.
--
Roedy Green Canadian Mind Productshttp://mindprod.com

"Danish studies of 10,000 birds killed revealed that almost all died in
collisions with buildings, cars and wires; only 10 were killed by windmills.
Alternative energy sources are absolutely necessary.
Global warming will kill birds and bats, as well as other species,
in much greater numbers than wind power."
~ Dr. David Suzuki
Thank you. That would be a more general way to do it.
Currently I am searching for ':', then if not found, a '.'.
Trying to parse a time string that may contain milliseconds and return
a Date object. SimpleDateFormat wasn't handling fractions of a second.
e.g.,
char timeSep = ':'; // when you 'Assume' ...
int indexOf = strDate.lastIndexOf(timeSep);
// continue on at charAt(indexOf) to find the milli separator
and handle fractional seconds

Doug Nickerson
 
L

Lew

Thank you. That would be a more general way to do it.
Currently I am searching for ':', then if not found, a '.'.
Trying to parse a time string that may contain milliseconds and return
a Date object.

<http://java.sun.com/javase/6/docs/api/java/text/DateFormat.html#parse
(java.lang.String)>

SimpleDateFormat wasn't handling fractions of a second.

Huh? Did you read the Javadocs for SimpleDateFormat?

<http://java.sun.com/javase/6/docs/api/java/text/
SimpleDateFormat.html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top