Time comes in following format: 08-11 20:03:17.182:
Parse into milliseconds
@param day string of format 08-11
@param hours string of format 20:03:17.182:
@return
345217
private long parseTime(String day, String hours)
    {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        Date utcDate = new Date();
        try {
            utcDate = format.parse(day.concat(" " + hours));
        } catch (Exception e) {

        }
        return utcDate.getTime();
    }
1302071
public String getFMDate() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(this);
        StringBuilder sb = new StringBuilder(15);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        
        if (hour == 0 && hasTime) {
            hour = 24;
            cal.add(Calendar.DAY_OF_MONTH, -1);
        }
        
        addFMPiece(sb, cal.get(Calendar.YEAR) - 1700, 0);
        addFMPiece(sb, cal.get(Calendar.MONTH) + 1, 2);
        addFMPiece(sb, cal.get(Calendar.DAY_OF_MONTH), 2);
        
        if (hasTime) {
            sb.append('.');
            addFMPiece(sb, hour, 2);
            addFMPiece(sb, cal.get(Calendar.MINUTE), 2);
            addFMPiece(sb, cal.get(Calendar.SECOND), 2);
            addFMPiece(sb, cal.get(Calendar.MILLISECOND), 2);
            
            for (int i = sb.length() - 1; i >= 0; i--) {
                char c = sb.charAt(i);
                
                if (c == '0') {
                    sb.deleteCharAt(i);
                } else if (c == '.') {
                    sb.deleteCharAt(i);
                    break;
                } else {
                    break;
                }
            }
        }
        
        return sb.toString();
    }
476929
public static final Date parseTime(String value)
   {
      Date result = null;
      if (value != null && value.length() != 0)
      {
         try
         {
            result = TIME_FORMAT.get().parse(value);
         }

         catch (ParseException ex)
         {
            // Ignore parse errors
         }
      }
      return result;
   }
1101472
def formatTimeOfDay(milliseconds, format = "%I:%M %p" )
      format ||= "%I:%M %p"
      timeOfDay = ""
      timeOfDay = Time.at(milliseconds.to_i/1000).utc.strftime(format) if milliseconds
   end
936040
private static String formatTime(int length, long time) {
        Calendar cal = Calendar.getInstance();
        if (time > -1) cal.setTimeInMillis(time);
        StringBuilder sb = new StringBuilder(length);
        int month = cal.get(Calendar.MONTH) + 1;
        int day = cal.get(Calendar.DAY_OF_MONTH);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        int seconds = cal.get(Calendar.SECOND);
        sb.append(cal.get(Calendar.YEAR)).append('-');
        if (month < 10) sb.append('0');
        sb.append(month).append('-');
        if (day < 10) sb.append('0');
        sb.append(day).append(' ');
        if (hour < 10) sb.append('0');
        sb.append(hour).append(':');
        if (minute < 10) sb.append('0');
        sb.append(minute).append(':');
        if (seconds < 10) sb.append('0');
        sb.append(seconds);
        if (length > 20) {
            int millis = cal.get(Calendar.MILLISECOND);
            sb.append('.');
            if (millis < 10) {
                sb.append("00");
            } else if (millis < 100) {
                sb.append('0');
            }
            sb.append(millis);
        }
        return sb.toString();
    }
929400
public static Date parse(String date) {
    try {
      int offset = 0;

      // extract year
      int year = parseInt(date, offset, offset += 4);
      if (checkOffset(date, offset, '-')) {
        offset += 1;
      }

      // extract month
      int month = parseInt(date, offset, offset += 2);
      if (checkOffset(date, offset, '-')) {
        offset += 1;
      }

      // extract day
      int day = parseInt(date, offset, offset += 2);
      // default time value
      int hour = 0;
      int minutes = 0;
      int seconds = 0;
      int milliseconds =
          0; // always use 0 otherwise returned date will include millis of current time

      // if the value has no time component (and no time zone), we are done
      boolean hasT = checkOffset(date, offset, 'T');

      if (!hasT && (date.length() <= offset)) {
        Calendar calendar = new GregorianCalendar(year, month - 1, day);

        return calendar.getTime();
      }

      if (hasT) {

        // extract hours, minutes, seconds and milliseconds
        hour = parseInt(date, offset += 1, offset += 2);
        if (checkOffset(date, offset, ':')) {
          offset += 1;
        }

        minutes = parseInt(date, offset, offset += 2);
        if (checkOffset(date, offset, ':')) {
          offset += 1;
        }
        // second and milliseconds can be optional
        if (date.length() > offset) {
          char c = date.charAt(offset);
          if (c != 'Z' && c != '+' && c != '-') {
            seconds = parseInt(date, offset, offset += 2);
            if (seconds > 59 && seconds < 63) {
              seconds = 59; // truncate up to 3 leap seconds
            }
            // milliseconds can be optional in the format
            if (checkOffset(date, offset, '.')) {
              offset += 1;
              int endOffset = indexOfNonDigit(date, offset + 1); // assume at least one digit
              int parseEndOffset = Math.min(endOffset, offset + 3); // parse up to 3 digits
              int fraction = parseInt(date, offset, parseEndOffset);
              milliseconds = (int) (Math.pow(10, 3 - (parseEndOffset - offset)) * fraction);
              offset = endOffset;
            }
          }
        }
      }

      // extract timezone
      if (date.length() <= offset) {
        throw new IllegalArgumentException("No time zone indicator");
      }

      TimeZone timezone;
      char timezoneIndicator = date.charAt(offset);

      if (timezoneIndicator == 'Z') {
        timezone = TIMEZONE_Z;
      } else if (timezoneIndicator == '+' || timezoneIndicator == '-') {
        String timezoneOffset = date.substring(offset);
        // 18-Jun-2015, tatu: Minor simplification, skip offset of "+0000"/"+00:00"
        if ("+0000".equals(timezoneOffset) || "+00:00".equals(timezoneOffset)) {
          timezone = TIMEZONE_Z;
        } else {
          // 18-Jun-2015, tatu: Looks like offsets only work from GMT, not UTC...
          //    not sure why, but it is what it is.
          String timezoneId = GMT_ID + timezoneOffset;
          timezone = TimeZone.getTimeZone(timezoneId);
          String act = timezone.getID();
          if (!act.equals(timezoneId)) {
            /* 22-Jan-2015, tatu: Looks like canonical version has colons, but we may be given
             *    one without. If so, don't sweat.
             *   Yes, very inefficient. Hopefully not hit often.
             *   If it becomes a perf problem, add 'loose' comparison instead.
             */
            String cleaned = act.replace(":", "");
            if (!cleaned.equals(timezoneId)) {
              throw new IndexOutOfBoundsException(
                  "Mismatching time zone indicator: "
                      + timezoneId
                      + " given, resolves to "
                      + timezone.getID());
            }
          }
        }
      } else {
        throw new IndexOutOfBoundsException(
            "Invalid time zone indicator '" + timezoneIndicator + "'");
      }

      Calendar calendar = new GregorianCalendar(timezone);
      calendar.setLenient(false);
      calendar.set(Calendar.YEAR, year);
      calendar.set(Calendar.MONTH, month - 1);
      calendar.set(Calendar.DAY_OF_MONTH, day);
      calendar.set(Calendar.HOUR_OF_DAY, hour);
      calendar.set(Calendar.MINUTE, minutes);
      calendar.set(Calendar.SECOND, seconds);
      calendar.set(Calendar.MILLISECOND, milliseconds);

      return calendar.getTime();
      // If we get a ParseException it'll already have the right message/offset.
      // Other exception types can convert here.
    } catch (IndexOutOfBoundsException | IllegalArgumentException e) {
      throw new RuntimeException("Not an RFC 3339 date: " + date, e);
    }
  }
1351263
public String formatTimeInterval(final long milliseconds) {
		long curMilliseconds = milliseconds;
		final StringBuilder sb = new StringBuilder().append("PT");
		final long hours = TimeUnit.MILLISECONDS.toHours(curMilliseconds);
		if (hours < 10)
			sb.append('0');
		sb.append(hours).append('H');
		curMilliseconds -= TimeUnit.HOURS.toMillis(hours);

		final long minutes = TimeUnit.MILLISECONDS.toMinutes(curMilliseconds);
		if (minutes < 10)
			sb.append('0');
		sb.append(minutes).append('M');
		curMilliseconds -= TimeUnit.MINUTES.toMillis(minutes);

		final long seconds = TimeUnit.MILLISECONDS.toSeconds(curMilliseconds);
		if (seconds < 10)
			sb.append('0');
		sb.append(seconds);
		curMilliseconds -= TimeUnit.SECONDS.toMillis(seconds);

		if (curMilliseconds > 0)
			sb.append('.').append(curMilliseconds);

		sb.append('S');
		return sb.toString();
	}
1159327
private static void convertDateString(String str) {
        try {
            Date date = Utils.dateFromString(str);
            display("Date to millis: " + date.getTime());
        } catch (Exception e) {
        }
    }
1151360
public static String elasticSearchTimeFormatToISO8601(String time) {
        try {
            DateTime dt = DateTime.parse(time, ES_DATE_FORMAT_FORMATTER);
            return getISO8601String(dt);
        } catch (IllegalArgumentException e) {
            return time;
        }
    }
479630
public static Calendar parse(final String date, final String format) {
		return parse(date, DateTimeFormat.forPattern(format));
	}
1079515
public String doFormatDate(long date) {
        buf.setLength(0);
        gc.setTimeInMillis(date);

        int day_of_week = gc.get(Calendar.DAY_OF_WEEK);
        int day_of_month = gc.get(Calendar.DAY_OF_MONTH);
        int month = gc.get(Calendar.MONTH);
        int year = gc.get(Calendar.YEAR);
        int century = year / 100;
        year = year % 100;

        int hours = gc.get(Calendar.HOUR_OF_DAY);
        int minutes = gc.get(Calendar.MINUTE);
        int seconds = gc.get(Calendar.SECOND);

        buf.append(DAYS[day_of_week]);
        buf.append(',');
        buf.append(' ');
        StringUtils.append2digits(buf, day_of_month);

        buf.append(' ');
        buf.append(MONTHS[month]);
        buf.append(' ');
        StringUtils.append2digits(buf, century);
        StringUtils.append2digits(buf, year);

        buf.append(' ');
        StringUtils.append2digits(buf, hours);
        buf.append(':');
        StringUtils.append2digits(buf, minutes);
        buf.append(':');
        StringUtils.append2digits(buf, seconds);
        buf.append(" GMT");
        return buf.toString();
    }
512125
@Pure
	@Inline(value = "(long) (($1).doubleValue() * $2.MILLIS_IN_DAY)", imported = {TimeExtensions.class})
	public static long days(Number days) {
		return (long) (days.doubleValue() * MILLIS_IN_DAY);
	}
569871
public static Date calculatePastDate(int days) {
        final Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -days);

        return cal.getTime();
    }
102185
public static String format(Date date) {
    Calendar calendar = new GregorianCalendar(TIMEZONE_Z, Locale.US);
    calendar.setTime(date);

    // estimate capacity of buffer as close as we can (yeah, that's pedantic ;)
    int capacity = "yyyy-MM-ddThh:mm:ss.sssZ".length();
    StringBuilder formatted = new StringBuilder(capacity);
    padInt(formatted, calendar.get(Calendar.YEAR), "yyyy".length());
    formatted.append('-');
    padInt(formatted, calendar.get(Calendar.MONTH) + 1, "MM".length());
    formatted.append('-');
    padInt(formatted, calendar.get(Calendar.DAY_OF_MONTH), "dd".length());
    formatted.append('T');
    padInt(formatted, calendar.get(Calendar.HOUR_OF_DAY), "hh".length());
    formatted.append(':');
    padInt(formatted, calendar.get(Calendar.MINUTE), "mm".length());
    formatted.append(':');
    padInt(formatted, calendar.get(Calendar.SECOND), "ss".length());
    formatted.append('.');
    padInt(formatted, calendar.get(Calendar.MILLISECOND), "sss".length());
    formatted.append('Z');
    return formatted.toString();
  }
314943
function formatDatetime(date) {
  date = new Date(date);
  var hour = date.getHours();
  var minutes =
    date.getMinutes() < 10
      ? '0' + date.getMinutes().toString()
      : date.getMinutes();

  return formatDate(date) + ' ' + hour + ':' + minutes;
}
1021777
public static CharSequence getJSDate(Calendar calendar)
	{
		StringBuilder dateJavascript = new StringBuilder();
		dateJavascript.append("new Date(");
		dateJavascript.append(calendar.get(Calendar.YEAR)).append(',');
		dateJavascript.append(calendar.get(Calendar.MONTH)).append(',');
		dateJavascript.append(calendar.get(Calendar.DAY_OF_MONTH)).append(',');
		dateJavascript.append(calendar.get(Calendar.HOUR_OF_DAY)).append(',');
		dateJavascript.append(calendar.get(Calendar.MINUTE)).append(',');
		dateJavascript.append(calendar.get(Calendar.SECOND)).append(',');
		dateJavascript.append(calendar.get(Calendar.MILLISECOND));
		dateJavascript.append(')');

		return dateJavascript.toString();
	}
583149
public static Integer getDay(Day day)
   {
      Integer result = null;
      if (day != null)
      {
         result = DAY_MAP.get(day);
      }
      return (result);
   }