converting epoch time to human readable format SDF
Hi ,
Trying to convert the following epoch time say ( 1327486488 676088 ) to SDF using XHTML Does anyone know if this is possible to do inside xhtml 1.0 ? Thanks |
To SDF? Using XHTML? XHTML is a content description language, and has no imperatives, nor facilities for data conversion.
If you can use Javascript (for example, if the XHTML is to be displayed in a standard web browser), you can create a Date object for the conversion: Code:
var date = new Date(1000 * epoch); If you encapsulate the epoch times in the XHTML content using for example a <span class="datemagic">epoch</span>, you should be able to use the onLoad handler for the body element to run a Javascript function that uses the Javascript DOM to convert the epoch numbers to a human-readable string in local time. (It would also mean that without Javascript, users would see the epoch numbers instead.) Although dynamic HTML is not recommended at all with XHTML content, in this case only the plain text string would be modified, and it should be completely safe. Actually, it might be pretty nifty in any case: the page could display the times in local time, without any intervention from the server. 1327486488 seconds since epoch is "Wed Jan 25 10:14:48 2012 UTC", but I have no idea what the 676088 refers to, or how it affects the date. |
I have tried using this but had no luck in getting the correct format
Code:
<h:outputText value="#{timestamp}"> Have you ever used this above ? |
Hi,
this site has all the conversions in one place, take what you need and implement it in your site. good luck |
Quote:
If you do use some framework (instead of publishing that XHTML as-is to clients), then you need to check the framework documentation. They differ, at least in the details. If you do not use any server-side application or framework, but publish the XHTML content as-is, then the Javascript route is the one I would seriously recommend. In Javascript the conversion is very simple, and all sane browsers support the DOM interface you can use to convert the date/timestamps. (In fact, I do believe it would be easy to transform even text times in UTC to epoch time, then to local time using the user's preferred locale on the client side. If you want, I can try and post a real-life example you can try in your browser. Note that this approach also works even if you do use a server-side application framework; you just "post-process" the date/timestamps client-side.) The page lithos linked to looks very good; it contains both examples, and links to implementations in different languages and situations. Thanks, lithos. |
All times are GMT -5. The time now is 10:55 AM. |