Questions tagged [timeunit]

55 questions
2
votes
1 answer

Is the TimeUnit class broken?

I noticed a strange behaviour of the TimeUnit class, so I created this minimal example to reproduce it. long differenceInDays; Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTimeInMillis(1466062306000l); // Thu…
Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
2
votes
3 answers

Formatting milliseconds to hh:mm:ss format

I am having milliseconds value and want to display the time subtracting 5 minutes from current milliseconds value in hh:mm:ss format. Code String str = String.format("%02d:%02d:%02d", …
Sash_KP
  • 5,551
  • 2
  • 25
  • 34
1
vote
1 answer

timeUnit does not work after a flatten and flod transformation

Is it possible to use timeUnit after a flatten and flod transformation? In the example below it doesnt work! If I remove the timeUnit from the x axis it plots, but without the good things that come with the timeUnit. Thanks This is an example code…
1
vote
0 answers

Clock Thread for a countdown in Java

I have a questions game ready in Java, with a counter time for each question. Players have 10 seconds to answer each question. To implement the counter, I maked a Clock class that calls the bot (the game implementer class) using a command class that…
Joseph
  • 41
  • 6
1
vote
1 answer

javafx label message showing with timer does not work

So im trying to show a message in javafx on a label and then make it disapear after 1 second. Im able to show the message as desired but i cannot make it dissapear. Actually my problem is that i never appear. So if i use only…
1
vote
1 answer

Convert microseconds to milliseconds without loss of precision and format as date-time in Java

How can I convert incoming long time value in microseconds into milliseconds and then format that to data time stamp as below: yyyyMMdd-HH:mm:ss.SSS I am using Java SimpleDateFormat to format the long value to the timestamp. But, converting the…
Jparak
  • 19
  • 1
  • 3
1
vote
1 answer

Performance hit for using TimeUnit conversion in Java

I was wondering if there is any performance hit (even if it is minimal) to using TimeUnit conversion. e.g. TimeUnit.MINUTES.toMillis(5) vs 300000 If this is a method that will be called frequently and it has to run the toMillis every time is there…
Kirit
  • 389
  • 2
  • 3
  • 11
1
vote
1 answer

TimeUnit on floating values

I created method like this, where I have 2 inputs. first is type (e.g. 'd', 'h') second is value (e.g. "15", "0.5") I created function to convert it to minutes like this: public Float toMinutes(char type, String value) { Float minutes = 0f; …
degath
  • 1,530
  • 4
  • 31
  • 60
1
vote
4 answers

Convert hh:mm:ss to mmm:ss

I have a Java function that convert seconds to an specific format (hh:mm:ss): public static String formatChronometer(long seconds) { return String.format("%02d:%02d:%02d", TimeUnit.SECONDS.toHours(seconds), …
aseolin
  • 1,184
  • 3
  • 17
  • 35
1
vote
1 answer

Express 24 hours in any Java TimeUnit

If my time unit is of type seconds and cycle duration is 20 sec after 86400/20 = 4320 cycles, 24 hours are passed. long numberOfCyclesToReach24Hours(long cycleDuration, TimeUnit unit) { // if I knew that unit is of type seconds I could …
radio
  • 897
  • 2
  • 10
  • 25
1
vote
0 answers

How to start decreasing a duration stored in Firebase as string? Please see details

I'm developing an android app and I have opted users to choose the duration and then I store it on Firebase as a string like this: hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(duration), …
Hammad Nasir
  • 2,889
  • 7
  • 52
  • 133
1
vote
2 answers

Java/Android: Native API to transform hours, minutes and seconds in milliseconds

I have created my own method to transform hours, minutes and seconds in milliseconds. It seems to work fine. I would prefer to use some Java/Android API to do this task. TimeUnit provides me the reverse: milliseconds to hours, minutes and…
Thom Thom Thom
  • 1,279
  • 1
  • 11
  • 21
1
vote
1 answer

JAVAFX, Countdown doesn't work

The count down does not work. I'm triggering it through a button. public void startCountDown() { timer.schedule(new TimerTask() { @Override public void run() { Platform.runLater(new Runnable() { public void run()…
Sh0ck
  • 97
  • 2
  • 12
1
vote
1 answer

CountDownTimer Android

I am trying to countdown to an event in android. the date and time for the event is stored in the database, but the Countdown returns more days than it should. This is what have tried. String EventDate="2013-12-26 15:00:00"; SimpleDateFormat…
olakunle
  • 851
  • 1
  • 7
  • 9
1
vote
2 answers

Java TimeUnit - Setup for a week's time unit

I am trying to work on some methods and a response for an action/"command" being able to be used one time a week (spam prevention). My only problem is how to set my java time to set as a week. This is what I have: public static long…