LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-25-2012, 05:51 AM   #1
nano2
Member
 
Registered: May 2007
Posts: 100

Rep: Reputation: 15
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
 
Old 01-25-2012, 12:37 PM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
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);
var text = date.toString();
The current UNIX epoch time is seconds since 1970-01-01 00:00:00 UTC; Javascript uses milliseconds since the same epoch. That's where the multiply-by-thousand comes from.

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.

Last edited by Nominal Animal; 01-25-2012 at 12:41 PM.
 
Old 01-26-2012, 02:52 AM   #3
nano2
Member
 
Registered: May 2007
Posts: 100

Original Poster
Rep: Reputation: 15
I have tried using this but had no luck in getting the correct format

Code:
    <h:outputText value="#{timestamp}">  
                        <f:convertDateTime dateStyle="full" />  
    </h:outputText>

Have you ever used this above ?
 
Old 01-26-2012, 02:56 AM   #4
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Hi,

this site has all the conversions in one place, take what you need and implement it in your site.

good luck
 
Old 01-26-2012, 04:15 AM   #5
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Quote:
Originally Posted by nano2 View Post
Have you ever used this above ?
No, I don't use Java server-side. Like I said, XHTML does not have any conversion facilities of its own. That syntax is parsed on the server side, most likely in some JSF (JavaServer Faces) or other server application framework. (XHTML is just the base storage format there, a sensible one because it can also be sent to a client, without any conversion, and handled as XML in the server application.) It will not work if you supply that XHTML to a client directly.

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.

Last edited by Nominal Animal; 01-26-2012 at 04:17 AM.
 
  


Reply

Tags
html, programing


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Human readable output from HP-UX Ejdaha Linux - Newbie 6 05-09-2013 02:05 AM
[SOLVED] Convert field from epoch to human readable sebelk Programming 6 01-08-2012 02:13 AM
Converting a date in MySQL format to human readable in Perl resetreset Programming 7 02-11-2009 07:14 AM
Java Epoch time to Human Readable (using Date) true_atlantis Programming 1 05-09-2008 05:13 PM
UNIX time stamp to readable format+PHP vargadanis Programming 1 10-10-2006 05:55 PM


All times are GMT -5. The time now is 09:11 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration