我目前正在将一些c ++代码移植到ruby,我从zabbix返回一个日期值,它返回日期原语。
目前执行此操作的代码是:
private static final long SPLASH_DURATION = 2*1000;
private long mStartTimestamp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
mStartTimestamp = System.currentTimeMillis();
new MyTask().execute();
}
class MyTask extends AsyncTask<Void, Void, Boolean>{
@Override
protected Boolean doInBackground(Void... params) {
// your logic here
return true;
}
@Override
protected void onPostExecute(Boolean success) {
super.onPostExecute(success);
// check your result here
if(success){
long timeStop = System.currentTimeMillis();
long delta = timeStop - mStartTimestamp;
if (delta >= SPLASH_DURATION) {
startMainActivity();
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startMainActivity();
}
}, SPLASH_DURATION - delta);
}
} else {
// handle the error
}
}
}
到目前为止我得到了这个:
Math.round(((new Date().valueOf()) - parseInt(result[0].value) * 1000) / 86400000)
不确定如何移植(result[0]['value'].to_i*1000) / 86400000).round
答案 0 :(得分:2)
1441972284808
看起来像Unix时间戳,以毫秒为单位,所以你可以试试这个:
time = Time.at(1441972284808 / 1000.0)
# => 2015-09-11 16:51:24 +0500
time.strftime('%j') # days quantity from start of the year
# => "254"