I want to change the date to the format dd/mm/yyyy but I did not succeed. I tried something like this:
<span class="postupdate">2015-03-01T14:28:28Z</span>
$(function(){
var d = $(".postupdate").html();
var n = d.toLocaleDateString();
d.html(n);
});
but I do not know how to to change the date it with javascript or jquery. whether to use a regex to change that date? Can someone help me?
You can use regex to parsing values of date. In bottom code, i used regex in .match() to parsing day, month, year of date.
$(".postupdate").text().match(/([^T]+)/)[0].split("-").reverse().join("/");
In your case, you can use this code:
$("span").text(function(i, text){
return text.match(/([^T]+)/)[0].split("-").reverse().join("/");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="postupdate">2015-03-01T14:28:28Z</span>
var d = $(".postupdate").html();
var date=new Date(d);
Then using X-Class package:
date.format('dd/mm/yyyy');
// 01/03/2015
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With