Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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")%> ?
 
Marshal
Posts: 67289
170
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
Marshal
Posts: 67289
170
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>
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!