Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to get the current time?

    Okay, I have looked everywhere and I can't find this. Searched this forum too.

    How do I get the current time?

    The can't use java's Calendar class. All that I want is to be able to get the right now, client side.

    #2
    I managed to find a solution, but it's not a good one because it uses deprecated Java:

    Code:
    import java.util.Date;
    .
    .
    .
    
      Date rightNow= new Date();
      int hour= rightNow.getHours();
      int min=rightNow.getMinutes();
    Can anyone suggest a solution that doesn't use deprecated Java?

    We can't use the Calendar code as that isn't supported client-side on GWT.

    Comment


      #3
      The deprecated code works just fine for getting the current time. The reason its deprecated is because it doesn't always handle Daylight savings time and leap years correctly. But that will never be a problem when just trying to get the current time, it'll always be correct in that case.

      Comment


        #4
        you could use DateTimeFormat

        String time[] = DateTimeFormat.getFormat("hh.mm.ss").format(new Date()).split("\\.");

        Then you will have in time[0] the hours, in time[1] minutes and in time[2] seconds. However as Strings.

        hope this helps.

        Comment


          #5
          Thank you both for these very helpful answers! I appreciate it.

          Brad

          Comment

          Working...
          X