To determine the websocket frame type you can use the following comparisons:
e.data instanceof ArrayBuffer
e.data instanceof Blob
typeof e.data === "string"
To determine the websocket frame type you can use the following comparisons:
e.data instanceof ArrayBuffer
e.data instanceof Blob
typeof e.data === "string"
Hier is ‘1524248879’ de C++ time_t
waarde zoals die bijvoorbeeld uit de C++ functie time( NULL )
komt.
new Date(1000 * 1524248879); "Sat Apr 21 2018 12:19:27 GMT+0200 (CEST)"
Vermenigvuldig met 1000 ( want C++ time_t
is seconden en JS Date()
is in milliseconden ) en in een JS new Date()
variable stoppen.
Vandaag een uur op zoek geweest naar een hele subtiele -op het eerste gezicht niet te verklaren- fout in een JS/jQuery project. Geen foutmelding, geen drama, maar alle Ajax aanroepen leken dingen te ‘vergeten’. Pas na een uur zag ik het.
Afronden doe je in javascript met Math.round()
.
Het afronden gebeurt altijd naar de dichtsbijzijnde integer, dus:
Math.round(23.1) //levert 23 op Math.round(23.9) //levert 24 op Math.round(23.5) //levert 24 op
Om op 1 decimaal nauwkeurig af te ronden gebruik je de volgende constructie:
resultaat=Math.round(23.123*10)/10 //levert 23.1 op
De algemene regel bij op x decimalen afronden is:
Math.round()
uit op het resultaat.