/**
DateTime
-------
Author: Jamal BOUIZEM
Date: 20/02/2015
Version: 1.0.0
*/
var DateTime = (function(){
return {
instance: function(spec){
var that = {
h: spec.h || 0,
m: spec.m || 0,
s: spec.s || 0
};
var d = new Date();
var str = "";
function __init__(h, m, s)
{
that.h = h;
that.m = m;
that.s = s;
d.setHours(that.h);
d.setMinutes(that.m);
d.setSeconds(that.s);
};
that.get = function(){
d.setHours(that.h);
d.setMinutes(that.m);
d.setSeconds(that.s);
return d;
};
that.set = function(h, m, s){
__init__(h, m, s);
};
that.convertSecs = function(){
return (that.h * 3600) + (that.m * 60) + that.s;
};
that.secsToDate = function(seconds){
var ts = seconds % 60;
var tm = (seconds/60) % 60;
var th = (seconds/3600) % 60;
return DateTime.instance({ h: parseInt(th), m: parseInt(tm), s: parseInt(ts) });
};
that.add = function(d){
return that.secsToDate(that.convertSecs() + d.convertSecs());
};
that.subtract = function(d){
return that.secsToDate(that.convertSecs() - d.convertSecs());
};
__init__(that.h, that.m, that.s);
return that;
}
}
})();
fonte
2015-02-20 11:04:31
Che tipo di datetime rappresentano questi numeri in virgola mobile? – deceze
Questi sono una serie di secondi, a partire da zero. È solo una serie di punti rappresentati da quando si sono verificati. – jhanifen
Penso che il problema che stiamo avendo qui è che i tuoi esempi che vuoi convertire non hanno senso. Si suppone che sia il numero di secondi da un determinato momento (1,3 secondi dopo il 1 gennaio 1970?) –