Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Converting MYSQL DATETIME to ANDROID CALENDER object
- private Calendar datetime2Calender(String oldDate)
- {
- // String oldDate = "11/25/2014 12:00:00 PM";
- Calendar cal = null;
- try
- {
- int dd, mm, yy, hh, min, ss;
- String ampm;
- int first, sec;
- first = 0;
- sec = oldDate.indexOf('/');
- mm = Integer.parseInt(oldDate.substring(first, sec));
- oldDate = oldDate.substring(sec + 1, oldDate.length());
- first = 0;
- sec = oldDate.indexOf('/');
- dd = Integer.parseInt(oldDate.substring(first, sec));
- oldDate = oldDate.substring(sec + 1, oldDate.length());
- first = 0;
- sec = oldDate.indexOf(' ');
- yy = Integer.parseInt(oldDate.substring(first, sec));
- oldDate = oldDate.substring(sec + 1, oldDate.length());
- first = 0;
- sec = oldDate.indexOf(':');
- hh = Integer.parseInt(oldDate.substring(first, sec));
- oldDate = oldDate.substring(sec + 1, oldDate.length());
- first = 0;
- sec = oldDate.indexOf(':');
- min = Integer.parseInt(oldDate.substring(first, sec));
- oldDate = oldDate.substring(sec + 1, oldDate.length());
- first = 0;
- sec = oldDate.indexOf(' ');
- ss = Integer.parseInt(oldDate.substring(first, sec));
- oldDate = oldDate.substring(sec + 1, oldDate.length());
- first = 0;
- sec = oldDate.length();
- ampm = oldDate.substring(first, sec);
- if (ampm.equalsIgnoreCase("pm"))
- hh = hh + 12;
- else if (hr == 12)
- hr = 0;
- cal = Calendar.getInstance();
- cal.set(yy, mm - 1, dd, hh, min, ss);
- return cal;
- } catch (Exception e)
- {
- }
- return cal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement