我正在接受这个代码的一些小事。我的输出看起来像这样。 “29天,29天,0小时,29分钟”。代码之外唯一的变量是toon.lastModified。它可能像1431769709000。代码的任务是告诉从现在开始已经过去的mutch时间,直到JSON发生了变化。我觉得问题是+用于添加数字和相互设置字符串。
var nowTime = new Date()
var timeStamp = nowTime.getTime()
var lastModTS = ((timeStamp-toon.lastModified)/1000).toFixed(0)
var lastModS = (lastModTS%60)
var lastModMin = (((lastModTS-lastModS)/60)%60)
var lastModH = (((lastModTS-(lastModS+lastModMin*60))/60)%24)
var lastModDay = (Math.floor((lastModTS-(lastModS+lastModMin*60+lastModH*60^2))/(24*60^2)))
var sinceLastMod=""
if (lastModDay==1){
sinceLastMod=lastModDay+" day, "
} else if (lastModDay>1){
sinceLastMod=lastModDay+" days, "
} if (lastModH==1){
sinceLastMod=sinceLastMod+lastModH+" hour, "
} else if (lastModH==0&&lastModDay==0){
sinceLastMod=""
} else {
sinceLastMod=sinceLastMod+sinceLastMod+lastModH+" hours, "
} if (lastModMin==1){
sinceLastMod=lastModDay+" minute, "
} else if (lastModMin==0&&lastModH==0&&lastModDay==0){
sinceLastMod=">1 minute"
} else if (lastModMin>1){
sinceLastMod=sinceLastMod+lastModMin+" minutes"
}
return sinceLastMod //it does not look like this in the code, as it is retuned in an array
EDIT 发现了另一件事 在lastModDay结束时,Google不会进行expotensial,我不得不将它改为60 * 60才能获得它。
答案 0 :(得分:0)
这一行:
static void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager,
final int appWidgetId) {
final Handler mHandler = new Handler();
TimerTask minuteTask = new TimerTask() {
@Override
public void run() {
mHandler.post(new Runnable() {
@Override
public void run() {
//Do Stuff
});
}
};
timer = new Timer();
// schedule the task to run starting now and then every minute
timer.scheduleAtFixedRate(minuteTask, 0l, 1000 * 60);
}
应该是:
static void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager,
final int appWidgetId) {
TimerTask minuteTask = new TimerTask() {
@Override
public void run() {
//Do stuff
}
};
timer = new Timer();
// schedule the task to run starting now and then every minute
timer.scheduleAtFixedRate(minuteTask, 0l, 1000 * 60);
}
删除其中一个sinceLastMod=sinceLastMod+sinceLastMod+lastModH+" hours, "
变量。你已经在那里两次了。