Convert simple Java firmware to Java format

I tried to find the answer to this for some time today, and there is so much conflicting information ....

What I would like to do is get the current unix timestamp in android and then convert it to a format that allows me to getHours () and getMinutes ().

I am currently doing this:

int time = (int) (System.currentTimeMillis()); Timestamp ts = new Timestamp(time); mHour = ts.getHours(); mMinute = ts.getMinutes(); 

But this does not give me the correct value for the hour or minute (it returns 03:38 for the current time of the East Coast 13:33).

+7
android date unix timestamp
source share
5 answers

It works:

 final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); Date date = cal.getTime(); mHour = date.getHours(); mMinute = date.getMinutes(); 
+10
source share

Just use the Java Calendar class.

 Calendar c = new GregorianCalendar(); // This creates a Calendar instance with the current time mHour = c.get(Calendar.HOUR); mMinute = c.get(Calendar.MINUTE); 

Also note that your Android emulator will return the time in GMT by the current time. I recommend testing this type of code on a real device.

+8
source share

Take a look at this.

Hope you need it.

Android simple date format

Good luck !!

+2
source share
 int time = (int) (System.currentTimeMillis()); 

here you should use long instead of int .

+2
source share

Using the T ime class of the Google form is the best kind of work for this kind, it has good performance, and not like a calendar.

0
source share

All Articles