Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Converting unix timestamp in HTML

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Could you please explain, how to convert timestamp string to normal date in HTML table?

An entry in the table looks like this:

<td bgcolor="#f4f4f4">
<%#Eval("MDate")%>
<td bgcolor="#f4f4f4">
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Andrius Gasto wrote:
An entry in the table looks like this:

<td bgcolor="#f4f4f4">
<%#Eval("MDate")%>
<td bgcolor="#f4f4f4">


What do you mean by "entry in database"? Is the whole TD is coming from DB? If yes, then solution is not stright-forwward (ASAIK)

If you're using JSP, then try JSTL fmt


And welcome to JavaRanch
 
Andrius Gasto
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for a reply.

Well, I am taking data from the web site using API.

I tried doing something like this and it worked, however I had to use the java script:

date = <%#Eval("MDate")%>

var myDate = new Date(date * 1000);
date = myDate.toGMTString();

So I was interested if there is a way to do a straight conversion in this part <%#Eval("MDate")%>?
What I get in a <%#Eval("MDate")%> is a string like 1331554332 and I need to convert it to normal date.

 
Andrius Gasto
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please suggest a way of getting an array of strings from <%#Eval("MDate")%> ?
 
Sheriff
Posts: 67405
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you could tell us what tools and frameworks you are using. That snippet of code is not HTML, CSS, JavaScript, or JSP. What is it?
 
Andrius Gasto
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This part of the code is written in ASP.
 
Bear Bibeault
Sheriff
Posts: 67405
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, that explains it. ASP isn't discussed here.
 
Andrius Gasto
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I figured it myself. In case someone needs it:

<td bgcolor="#f4f4f4">
<script type="text/javascript">
date_conversion(<%#Eval("MDate")%>);
</script>
</td>

Javascript converts epoch to readable data and stores it in a table

<script type="text/javascript">
function date_conversion(date)
{
var myDate = new Date(date * 1000);
date = myDate.toGMTString();
var trimmed_date = date.substring(0, date.length-4) // Atmetamas GMT ir vienas tarpas
document.write(trimmed_date);
}
</script>
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic