Announcement

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

    how to get time from TimeItem

    Maybe a very silly question, but I couldn't find the method that gets the value (as long or Date) from a TimeItem. DateItem has getValueAsDate() method, what is the equivalence for TimeItem. Do you expect user to use DateTimeFormat to parse the TimeItem value string?

    Something like:

    TimeItem itemItem = new TimeItem();
    timeItem.setTimeFormatter(TimeDisplayFormat.TOSHORTTIME);

    DateTimeFormat formatter = DateTimeFormat.getFormat("h:m a");
    Date time = formatter.parse(timeItem.getValueAsString());

    Another question, TimeDisplayFormat.TOSHORTTIME does not print space between h:m and am/pm. Is this a bug?

    Thanks for your help.
    Last edited by mshen; 16 Oct 2014, 17:28.

    #2
    Please help! How do I get Date relative to epoch time from TimeItem input?

    I have a DateItem and a TimeItem, What I want is to combine the value from DateItem and TimeItem into one value. How do I do this?

    I tried the following code. It gives me the time since the beginning of today, not since epoch time. Thanks!

    imeItem itemItem = new TimeItem();
    timeItem.setTimeFormatter(TimeDisplayFormat.TOSHORTTIME);

    DateTimeFormat formatter = DateTimeFormat.getFormat("h:m a");
    Date time = formatter.parse(timeItem.getValueAsString());

    Comment


      #3
      Ok. The following worked.

      {
      Date date = dateItem.getValueAsDate();
      date.setHours(0);
      date.setMinutes(0);
      date.setSeconds(0);

      DateTimeFormat formatter = DateTimeFormat.getFormat("h:m a");
      Date time = formatter
      .parse(timeItem.getDisplayValue());
      int hours = time.getHours();
      int minutes = time.getMinutes();
      return new Date(date.getTime() + hours * 60 * 60 * 1000
      + minutes * 60 * 1000);
      }

      Originally posted by mshen View Post
      Please help! How do I get Date relative to epoch time from TimeItem input?

      I have a DateItem and a TimeItem, What I want is to combine the value from DateItem and TimeItem into one value. How do I do this?

      I tried the following code. It gives me the time since the beginning of today, not since epoch time. Thanks!

      imeItem itemItem = new TimeItem();
      timeItem.setTimeFormatter(TimeDisplayFormat.TOSHORTTIME);

      DateTimeFormat formatter = DateTimeFormat.getFormat("h:m a");
      Date time = formatter.parse(timeItem.getValueAsString());

      Comment


        #4
        See the Date and Time Format and Storage Overview.

        Comment

        Working...
        X