79445473

Date: 2025-02-17 13:01:46
Score: 1
Natty:
Report link

Rewriting the @mrres1 code in kotlin

 val dateFormat = SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
 val date = Date()

// Print current time
Log.d("TIME","Current Time: ${dateFormat.format(date)}")

// Use Calendar to add 10 hours
val calendar = Calendar.getInstance().apply {
    time = date
    add(Calendar.HOUR_OF_DAY, 10)
}

val newDate = calendar.time

// Print new time
Log.d("TIME","Time after 10 hours: ${dateFormat.format(newDate)}")

Output will be

Current Time: 05/14/2014 01:10:00
Time after 10 hours: 05/14/2014 11:10:00
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @mrres1
  • Low reputation (1):
Posted by: Qamar Abbas