Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current Time

Tags:

android

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
like image 394
Hans Wurst Avatar asked Aug 31 '10 16:08

Hans Wurst


People also ask

How can I get the current time and date?

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.

How do I get the current time in Python?

You can get the current time in python using datetime. now(). strftime("%H:%M:%S") from the DateTime module.

How do I get the current UTC time in Python?

Use datetime. datetime.datetime. utcnow() to get a datetime. datetime object representing the current UTC time.

How do I get the current time in Django?

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.


2 Answers

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.

like image 101
user223697 Avatar answered Sep 18 '22 21:09

user223697


int hours = new Time(System.currentTimeMillis()).getHours();
like image 24
Thorstenvv Avatar answered Sep 20 '22 21:09

Thorstenvv