• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Converting unix timestamp in HTML

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please suggest a way of getting an array of strings from <%#Eval("MDate")%> ?
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This part of the code is written in ASP.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic