四舍五入到最接近的15分钟间隔。 我想知道是否有办法让我向上或向下舍入到最近的15分钟间隔。我使用此函数,但是在H和H = 15分钟之间,我没有参数。
private lateinit var fileDir: File
private lateinit var items: MutableList<String>
private lateinit var itemsAdapter: ArrayAdapter<String>
private lateinit var listVIL: ListView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_todo1)
listVIL = findViewById(R.id.listVI)
try {
fileDir = File(Environment.getExternalStorageDirectory(), "todo.txt")
if (!fileDir.exists()) fileDir.createNewFile()
items = ArrayList(file.readLines())
itemsAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, items)
listVIL.adapter = itemsAdapter
} catch (e: Exception) {
Toast.makeText(applicationContext,e.toString(),Toast.LENGTH_LONG).show()
}
}
答案 0 :(得分:0)
舍入:
var d = new Date('2001-02-03T04:59:59.999Z'), rounded = new Date( d - d % 9e5 );
console.log( d ); console.log( rounded ); /* 1000 ms * 60 sec * 15 min = 900000 */
console.log( rounded.toJSON().replace(/.*-(..)-(..)T(..):(..).*/, 'image/type$1$2$3$4.png') );
舍入到最接近的15分钟:
var d = new Date('2001-02-03T04:52:30.000Z'),
rounded = new Date( Math.round(d / 9e5) * 9e5 );
console.log( d ); console.log( rounded );