Java – How to convert System.nanoTime to Seconds

We can just divide the nanoTime by 1_000_000_000, or use the TimeUnit.SECONDS.convert to convert it. Note 1 second = 1_000_000_000 nanosecond JavaExample.java package com.mkyong; import java.util.concurrent.TimeUnit; public class JavaExample { public static void main(String[] args) throws InterruptedException { long start = System.nanoTime(); Thread.sleep(5000); long end = System.nanoTime(); long elapsedTime = end – start; System.out.println(elapsedTime); // …

Read more

Python – How to delay few seconds

In Python, you can use time.sleep(seconds) to make the current executing Python program to sleep or delay a few seconds. import time time.sleep(1) # delays for 1 seconds time.sleep(10) # delays for 10 seconds time.sleep(60) # delays for 1 minute time.sleep(3600) # delays for 1 hour Full example. test_delay.py import time def main(): while True: …

Read more

Java – Convert date and time between timezone

In this tutorial, we will show you few examples (ZonedDateTime (Java 8), Date, Calendar and Joda Time) to convert a date and time between different time zones. All examples will be converting the date and time from (UTC+8:00) Asia/Singapore – Singapore Time Date : 22-1-2015 10:15:55 AM to (UTC-5:00) America/New_York – Eastern Standard Time Date …

Read more

Android time picker example

In Android, you can use “android.widget.TimePicker” class to render a time picker component to select hour and minute in a pre-defined user interface. In this tutorial, we show you how to render time picker component via android.widget.TimePicker in current page, and also in dialog box via android.app.TimePickerDialog. In addition, we also show you how to …

Read more