react native 计算时间差,天-时-分-秒

前端之家收集整理的这篇文章主要介绍了react native 计算时间差,天-时-分-秒前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//计算时间
var sendTime =this . props . obj .send_time;

console . log ( sendTime );

//当前时间
var nowTime = ( new Date ()). valueOf ();

console . log ( nowTime );

//差值
var date3 = nowTime - sendTime ;

console . log ( date3 );

//天
var days = Math . floor ( date3 / ( 24 * 3600 * 1000 ))
//时
var leave1 = date3 % ( 24 * 3600 * 1000 )
var hours = Math . floor ( leave1 / ( 3600 * 1000 ))
//分
var leave2 = leave1 % ( 3600 * 1000 )
var minutes = Math . floor ( leave2 / ( 60 * 1000 ))

//秒
var leave3 = leave2 % ( 60 * 1000 )
var seconds = Math . round ( leave3 / 1000 )

var disAndTimeText ;

if ( days > 0 ){
var myText = '600m ' + days + '天前'
disAndTimeText = < Text style = { styles . disAndTimeText }>{ myText }</ Text >
}

if ( days == 0 && hours > 0 ){
var myText = '600m ' + hours + '小时前'
disAndTimeText = < Text style = { styles . disAndTimeText }>{ myText }</ Text >
}

if ( days == 0 && hours == 0 && minutes > 0 ){
var myText = '600m ' + minutes + '分钟前'
disAndTimeText = < Text style = { styles . disAndTimeText }>{ myText }</ Text >
}

if ( days == 0 && hours == 0 && minutes == 0 && seconds > 0 ){
var myText = '600m 刚刚'
disAndTimeText = < Text style = { styles . disAndTimeText }>{ myText }</ Text >
}

猜你在找的React相关文章