0
  1. I'm learning Android a simple screen with user Information like name,Date of Birth and so on.
  2. All are Text View and Edit Text.
  3. In my pojo Date of Birth datatype is String.
  4. When I enter date and try to get the date it is showing as some long number I this it is date and time in milliseconds.
  5. Can any one help me to solve this.
Rakesh
  • 41
  • 1
  • 6

2 Answers2

0

If i understand your problem.. Try this...

Date d1 = new Date();
d1.setTime(time_in_milliseconds);

Calendar cal = Calendar.getInstance();
cal.setTime(d1);

And then you can get day,month, year..

int number_of_day = cal.get(Calendar.DAY_OF_MONTH)
0

Check this :

public Date getDateByFormat(String time, String format) {
    if (time == null || "".equals(time)) return null;
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.ENGLISH);
        return sdf.parse(time);
    } catch (ParseException e) {
        Log.d(Constants.TAG, "Could not parse date: " + time + " Due to: " + e.getMessage());
    }
    return null;
}

here format is your date string format. Like "yyyy-MM-dd HH:mm:ss"

Sayem
  • 4,891
  • 3
  • 28
  • 43