Verwenden von Momentjs mit React Native. Die folgende MomentT
Funktion analysiert das Datum/die Zeit gemäß dem angeforderten Format und es wird richtig formatiert angezeigt, aber es gibt mir eine bizarre Zeit anstatt der Zeit des Sonnenuntergangs. Es scheint tatsächlich zu ignorieren json.sys.sunset
(was in LA ist derzeit etwa 1470969909 in Unix-Zeit) und Parsing es als 4:36:09 pm, aber es sollte es als 7:45:09 Uhr analysieren. Was mache ich falsch?ReactNative/Moments Datum Parsing Problem
Hier ist der entsprechende Code:
var moment = require('moment');
var MomentT = function(tod) {
return moment(tod).format('h:mm:ss a');
};
module.exports = function(latitude, longitude) {
var url = `${rootUrl}&lat=${latitude}&lon=${longitude}`;
console.log(url);
return fetch(url)
.then(function(response){
return response.json();
})
.then(function(json){
return {
sunset: MomentT(json.sys.sunset)
}
})
.catch(function(error) {
console.log('There has been a problem with your fetch operation: ' + error.message);
throw error;
});
}