I am looking for a time output using jQuery, for example, would be great to know what time it is on the visitor's browser and the current day (friday,saturday,monday, etc...).
Is there any way to do it only with jQuery? I don't really like the way javascript handles time issues.
If you recommend any plugin, please tell me wich.
Thanks so much! Souza.
EDIT:
I'm looking to avoid substring javascript outputs, or convert the results.
Wouldn't be great to use
$("#setime").yourtime("day");
and give me the day? or
$("#setime").yourtime("hour", 24format);
and give you the hour in any format you need?
?
Try:
var currentTime = new Date();
It's not jQuery but it will do what you want.
You also have:
var month = currentTime.getMonth()
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
To play with.
Perhaps this is what you were looking for?
http://crossbreeze.github.com/jquery-sensible-datetime/
Download here: https://github.com/crossbreeze/jquery-sensible-datetime
If not, here is plain JS for you to reuse
<script type="text/javascript">
var weekday=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"," Saturday"];
var monthname=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
function formatDate(d) {
var text = "";
text += weekday[d.getDay()] + " ";
text += d.getDate() + " ";
text += monthname[d.getMonth()] + " ";
text += d.getFullYear();
var hh = d.getHours();
var mm = d.getMinutes();
if (hh<10) hh = "0"+hh;
if (mm<10) mm = "0"+mm;
return text +" "+hh+":"+mm;
}
$(document).ready(function () {
var d = new Date();
$("#dateDiv").text(formatDate(d));
});
</script>