[F.END] Date formatting w/ moment.js
This commit is contained in:
parent
9b25af24a0
commit
d4b515f062
|
@ -1,3 +1,4 @@
|
|||
// Require moment.js (with locales)
|
||||
function Get(yourUrl){
|
||||
var Httpreq = new XMLHttpRequest();
|
||||
Httpreq.open("GET",yourUrl,false);
|
||||
|
@ -7,17 +8,17 @@ function Get(yourUrl){
|
|||
|
||||
var json_obj = JSON.parse(Get("https://golem.linux.it/cgi/zerocalcare/main.py?interval=4weeks"));
|
||||
console.log("this is the JSON: "+JSON.stringify(json_obj));
|
||||
fmt_date = { weekday: 'short', month: 'long', day: 'numeric' };
|
||||
fmt_time = { hour: 'numeric', minute: 'numeric'};
|
||||
|
||||
moment.locale('it');
|
||||
for (i in json_obj) {
|
||||
var time_str;
|
||||
var date = new Date(json_obj[i]["DATETIME"])
|
||||
var date = moment(json_obj[i]["DATETIME"])
|
||||
console.log(JSON.stringify(json_obj[i]));
|
||||
document.write('<h5 class="widget-title" style="font-style: italic; color: #009000;">'+json_obj[i]["NAME"]+'</h5>');
|
||||
document.write("<div>📅 "+date.toLocaleDateString("it-IT", fmt_date)+"</div>");
|
||||
document.write("<div>📅 "+date.format("ddd D MMMM")+"</div>");
|
||||
if (json_obj[i]["ALLDAY"] == true)
|
||||
time_str = "Tutto il giorno"
|
||||
else
|
||||
time_str = date.toLocaleString("it-IT", fmt_time)
|
||||
time_str =date.format("H:mm")
|
||||
document.write("<div>⏰ "+time_str+"</div>");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue