kotlin set and show time and time difference

import java.util.*
import java.text.SimpleDateFormat
import java.time.format.DateTimeFormatter


fun main(args: Array<String>) {

    val str="2018-08-29 12:00:00"
    //set Specified  date format
    val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
	val date = sdf.parse(str);
    //get Specified  date
    System.out.println(date); 
    System.out.println(date.getTime());

    //current time to long
    var currentTime = Calendar.getInstance()
    System.out.println(currentTime.getTimeInMillis())
    //current time and Specified time  difference , 60000 is 1 minute
    val b= date.getTime()-currentTime.getTimeInMillis()
    System.out.println(b/60000)

    //get current time
    System.out.println(currentTime.getTime()) 
}

猜你喜欢

转载自blog.csdn.net/fdsafwagdagadg6576/article/details/82192486