| Author |
simpledateformat
|
divya kundapur
Ranch Hand
Joined: Aug 21, 2007
Posts: 110
|
|
Hi,
I have a date format of yyyy-MM-dd-HH.mm.ss.SSSSSS and need to convert it to yyyy-MM-dd HH:mm:ss.S
but say when i pass the date 2010-02-16-23.59.59.999000 i m getting the formated date as 2010-02-17 00:16:38.000
|
SCJP - 5.0
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2925
|
|
|
This I think is due to the different TIMEZONE. You can look at the SimpleDateFormat API to see the format for specifying the Timezone.
|
Mohamed Sanaulla | My Blog
|
 |
Prakash Krsihnan
Greenhorn
Joined: Jan 19, 2006
Posts: 4
|
|
|
Milliseconds is always three digit. Even if "SSSSSS" is given
|
"The greatest use of life is to spend it for something that will outlast it"
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2925
|
|
I told suggested to check with TIMEZONE as there was a difference between the 2 dates (~16 minutes if I am not wrong).
Update: and it looks like a difference of 1 day
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Prakash is right. You probably expect the 999000 to be read as 999, but it is read as 999000, then truncated to 0 (999000 % 1000 == 0).
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
divya kundapur
Ranch Hand
Joined: Aug 21, 2007
Posts: 110
|
|
But why is the date incrementing by 1 day.
|
 |
Prakash Krsihnan
Greenhorn
Joined: Jan 19, 2006
Posts: 4
|
|
If you convert "999000" ms to minute it comes to 17:38 and it added to date.
It advisable to use only SSS or S. Don't use more than three S for microseconds
|
 |
divya kundapur
Ranch Hand
Joined: Aug 21, 2007
Posts: 110
|
|
Prakash Krsihnan wrote:If you convert "999000" ms to minute it comes to 17:38 and it added to date.
It advisable to use only SSS or S. Don't use more than three S for microseconds
Thank you very much
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2925
|
|
Prakash Krsihnan wrote:If you convert "999000" ms to minute it comes to 17:38 and it added to date.
It advisable to use only SSS or S. Don't use more than three S for microseconds
Oh nice catch. It struck to me as a TIMEZONE issue.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Prakash Krsihnan wrote:If you convert "999000" ms to minute it comes to 17:38 and it added to date.
It advisable to use only SSS or S. Don't use more than three S for microseconds
So I was wrong - the 999000 isn't truncated at all but added as additional milliseconds.
|
 |
 |
|
|
subject: simpledateformat
|
|
|