Android Utililty Methods Calendar to Timestamp Convert

List of utility methods to do Calendar to Timestamp Convert

Description

The list of methods to do Calendar to Timestamp Convert are organized into topic(s).

Method

TimestampCalendar2Timestamp(Calendar c)
Calendar Timestamp
return new Timestamp(c.getTimeInMillis());
StringconvertToTimeStamp(Calendar cal)
Convert date to short time string
return convertToTimeStamp(cal, true);
StringconvertToTimeStamp(Calendar time, boolean showSeconds)
convert To Time Stamp
String hours = Integer.toString(time.get(Calendar.HOUR_OF_DAY));
if (hours.length() == 1) {
    hours = '0' + hours;
String minutes = Integer.toString(time.get(Calendar.MINUTE));
if (minutes.length() == 1) {
    minutes = '0' + minutes;
if (showSeconds) {
    String seconds = Integer.toString(time.get(Calendar.SECOND));
    if (seconds.length() == 1) {
        seconds = '0' + seconds;
    return hours + ":" + minutes + ":" + seconds;
} else {
    return hours + ":" + minutes;
TimestampnowAsTimestamp()
now As Timestamp
Calendar objCurrentCalendar = Calendar.getInstance();
return new Timestamp(objCurrentCalendar.getTimeInMillis());