Shailesh Shailesh - 1 year ago 74
HTML Question

Html element <time> date format without HH MM SS

I am using HTML

element to display the date.I have to display only date-part.From back-end I am getting date "13/07/2016 00:00:00" with HH MM SS.

I used below line to convert date-time to date.

<time class="meta" datetime="DD/MM/YYYY">13/07/2016 00:00:00</time>

But still output is same "13/07/2016 00:00:00".

I was referring :-
HTML time tag - correct date format

Answer Source

I think there is some confusion regarding tag.

According to MDN:

This element is intended to be used presenting dates and times in a machine readable format. This can be helpful for user agents to offer any event scheduling for user's calendar.

In your code, <time class="meta" datetime="DD/MM/YYYY">13/07/2016 00:00:00</time>, the output will not change by format you specify by datetime attribute, because it is meant for machine reading, but the text part of this tag that is 13/07/2016 00:00:00 will be visible on page to humans.

If you want to change format of output of this. I think you should use some sort of javascript to format this value, or for a hackish way, you can just split it by space and use first index for just date.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download