How to get the current time in Android?
When i use
int hours = java.sql.Time.this.getHours();
i get the error:
No enclosing instance of the type Time is accessible in scope
Example 1: Current time using datetime object Then, we used now() method to get a datetime object containing current date and time. Using datetime. strftime() method, we then created a string representing current time. If you need to create a time object containing current time, you can do something like this.
You can get the current time in python using datetime. now(). strftime("%H:%M:%S") from the DateTime module.
Use datetime. datetime.datetime. utcnow() to get a datetime. datetime object representing the current UTC time.
First, open the views.py file of your Django application and import the datetime module. Next, use the datetime. now() method to get the current date and time value.
Try this:
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
public static final int HOUR_OF_DAY Since: API Level 1 Field number for get and set indicating the hour of the day. HOUR_OF_DAY is used for the 24-hour clock. E.g., at 10:04:15.250 PM the HOUR_OF_DAY is 22.
int hours = new Time(System.currentTimeMillis()).getHours();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With