 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 2nd, 2008, 03:02 PM
|
|
Authorized User
|
|
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
millisec or fraction of seconds
this is a question regarding the time that the date-time function returns:
2008-05-07T11:24:35.876-04:00
the "876" here is the milli-seconds value or it is fractional seconds.
|
|

June 2nd, 2008, 03:20 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Well, if there's three digits then it's both. The actual number of digits you get back after the decimal point is system-dependent, so it's best to treat it as fractional seconds.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

June 2nd, 2008, 03:41 PM
|
|
Authorized User
|
|
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
So now if the date template returns
2008-05-30T20:42:01.9249999523162842Z,
if i keep three numbers after '.' and truncate rest, will it be the required millisecond value?
2008-05-30T20:42:01.924Z
if not how to convert this fractional seconds to milli seconds?
|
|

June 2nd, 2008, 04:00 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
It will be wrong by approximately 0.999952 of a millisecond.
In other words, it will be off by almost a full millisecond.
Do you care???
If not, leave it alone.
If you care, then you should round the number instead of just truncate.
|
|

June 2nd, 2008, 04:09 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I am very confused by your question. There are 1000 milliseconds in a second, so 1 second and 543 milliseconds is 1.534 seconds. What exactly is your problem?
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

June 2nd, 2008, 04:11 PM
|
|
Authorized User
|
|
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
mhkay:
well milliseconds can never have value more than 999. but what we see is 15 numbers. also 1.500 is the same as "1 min and 500 milliseconds" or "1 min and 5 milliseconds"
as an analogy: 1.5 years would mean 1 year and 6 months rather than 1 year and 5 months.
Old Pedant:
if i do round off, then i may have to manipulate the seconds/hours/or even date part.
For eg:
2008-05-30T23:59:59.9999999523162842Z
this date time value will make me do lot of string manipulation work.
(am i right?)
my requirement is 3 digits after the seconds part. and this should represent milliseconds. if there is a way to format this time stamp value so that just 3 digits are returned for the frac seconds part. so that i can readily consider this as milliseconds.
|
|

June 2nd, 2008, 04:30 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
If it really matters to you to round to the nearest millisecond rather than truncating, try format-dateTime($d,'[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]:[f001]')
However, it's highly unlikely that the value returned by the system is sufficiently precise that it really makes a meaningful difference whether you round or truncate the value.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

June 2nd, 2008, 06:34 PM
|
|
Authorized User
|
|
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Kay...
in our XI50 SOA appliance, the format-dateTime function is not supported unfortunately :(... what to do?
if you can give me the code of the format-dateTime template, i will try to import the same in my xsl.
|
|
 |