2

I am using android.text.format.Time and i need to have a function which gets a string and converts that string into a Time object. I initially stored the time object as string for some other reason. I just need to pasre teh string into Time object now. Code:

 Time time = new Time();
 String time = time.toString();

  Time t = new Time();
  t.parse(time);
  this.time = t;

Now

t.parse(time) 

gives a boolean value.

boolean value = time.parse(s)

Parameters: time - the string to parse Returns: true - if the resulting time value is in UTC time

1
  • 2
    So what is the question? It looks like you answered the question by yourself. Unless the Time does not have parse method and you are asking how to implement your one parse method. Commented Dec 14, 2012 at 8:57

1 Answer 1

4
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse("2012-12-14 14:05:59");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(date.getTime());
Time time = new Time();
time.set(int second, int minute, int hourOfDay, int monthDay, int month, int year);

// int second => calendar.get(Calendar.SECOND);
// etc minute, hourOfDay, monthOfDay, month, year...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.