Parses the supplied text and converts it to a Long
corresponding to that midnight in UTC on the specified date.

@return null if it fails to parsing using the specified
DateTimeFormat
508210
private Long string2long(String text, DateTimeFormat fmt) {
        
        // null or "" returns null
        if (text == null) return null;
        text = text.trim();
        if (text.length() == 0) return null;
        
        Date date = fmt.parse(text);
        return date != null ? UTCDateBox.date2utc(date) : null;
    }
285972
public long parseDate(String string) throws Exception
  {
    try {
      int strlen = string.length();

      if (strlen == 0)
        return 0;

      int i = skipWhitespace(string, strlen, 0);

      int ch = string.charAt(i);
      if (ch >= '0' && ch <= '9'
          || (ch == 'T' && i + 1 < strlen
              && string.charAt(i + 1) >= '0' && string.charAt(i + 1) <= '9'))
        return parseISO8601Date(string, i);

      CharBuffer cb = new CharBuffer();

      i = scan(string, 0, cb, true);
      if (cb.length() == 0 || ! Character.isDigit(cb.charAt(0)))
        i = scan(string, i, cb, true);

      int dayOfMonth = parseInt(cb);
      i = scan(string, i, cb, true);
      String smonth = cb.toString();
      int month;
      for (month = 0; month < 12; month++) {
        if (MONTH_NAMES[(int) month].equalsIgnoreCase(smonth))
          break;
      }

      if (month == 12)
        throw new Exception("Unexpected month: " + month);

      i = scan(string, i, cb, true);

      int year = parseInt(cb);
      if (cb.length() < 3 && year < 50)
        year += 2000;
      else if (cb.length() < 3 && year < 100)
        year += 1900;

      i = scan(string, i, cb, false);
      long timeOfDay = parseInt(cb) * 3600000;

      i = scan(string, i, cb, false);
      timeOfDay += parseInt(cb) * 60000;

      i = scan(string, i, cb, false);
      timeOfDay += parseInt(cb) * 1000;

      // XXX: gross hack
      if (year <= 1600)
        dayOfMonth--;

      long time = (MS_PER_DAY * (yearToDayOfEpoch(year)
                                 + monthToDayOfYear(month, isLeapYear(year))
                                 + dayOfMonth - 1)
                   + timeOfDay);

      try {
        i = scan(string, i, cb, false);
        for (int j = 0; j < cb.length(); j++) {
          if ((ch = cb.charAt(j)) == ';' || ch == ' ')
            cb.length(j);
        }

        ch = cb.length() > 0 ? cb.charAt(0) : 0;
        if (ch == '-' || ch == '+' || ch >= '0' && ch <= '9') {
          long zoneOffset;
          zoneOffset = parseInt(cb);
          zoneOffset = 60000 * (60 * (zoneOffset / 100) + zoneOffset % 100);

          time -= zoneOffset;

          setGMTTime(time);
        } else if (cb.equalsIgnoreCase("gmt") ||
                   cb.equalsIgnoreCase("utc")) {
          setGMTTime(time);
        } else {
          setLocalTime(time);
        }
      } catch (Exception e) {
        log.log(Level.FINER, e.toString(), e);
      }

      return _localTimeOfEpoch - _zoneOffset;
    } catch (Exception e) {
      log.log(Level.FINER, e.toString(), e);

      return Long.MAX_VALUE;
    }
  }
777980
public static DateTime parseTime(String timeString) {
		timeString = normalize(timeString);
		return parse(timeString, DatePattern.NORM_TIME_FORMAT);
	}
1285940
public static Date parseHttpDate(CharSequence txt, int start, int end) {
        int length = end - start;
        if (length == 0) {
            return null;
        } else if (length < 0) {
            throw new IllegalArgumentException("Can't have end < start");
        } else if (length > 64) {
            throw new IllegalArgumentException("Can't parse more than 64 chars," +
                    "looks like a user error or a malformed header");
        }
        return formatter().parse0(checkNotNull(txt, "txt"), start, end);
    }
439487
public Date parse(String dateString)
	throws ParseException
	{
		Date result = null;
		ParseException lastException = null;
		
		for (DateFormat format : inputFormats)
		{
			try
			{
				result = ((DateFormat) format.clone()).parse(dateString);	// DateFormat is not thread safe.
				lastException = null;
				break;
			}
			catch (ParseException e)
			{
				// Keep the first exception that occurred.
				if (lastException == null)
				{
					lastException = e;
				}
				// And just try the next input format.
			}
		}

		if (lastException != null)
		{
			throw lastException;
		}

		return result;
	}
662388
@Nullable
    public static Date parseDate(String dateValue, Collection<String> dateFormats) {
        return parseDate(dateValue, dateFormats, DEFAULT_TWO_DIGIT_YEAR_START);
    }
791777
@SuppressWarnings("unchecked")
    @Override
    public T parse(final String text) {
        
        try {
            return (T) parseMethod.invoke(type, text, formatter);
            
        } catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            throw new TextParseException(text, type, "Cannot suuport type.");
            
        } catch(DateTimeParseException e) {
            throw new TextParseException(text, type, e);
        }
        
    }
875141
protected static final Long parseUsingFallbacksWithColon(String text, DateTimeFormat timeFormat) {
        if (text.indexOf(':') == -1) {
            text = text.replace(" ", "");
            int numdigits = 0;
            int lastdigit = 0;
            for (int i = 0; i < text.length(); i++) {
                char c = text.charAt(i);
                if (Character.isDigit(c)) {
                    numdigits++;
                    lastdigit = i;
                }
            }
            if (numdigits == 1 || numdigits == 2) {
                // insert :00
                int colon = lastdigit + 1;
                text = text.substring(0, colon) + ":00" + text.substring(colon);
            }
            else if (numdigits > 2) {
                // insert :
                int colon = lastdigit - 1;
                text = text.substring(0, colon) + ":" + text.substring(colon);
            }
            return parseUsingFallbacks(text, timeFormat);
        }
        else {
            return null;
        }
    }
707798
public static String fromUnixtime(long unixtime, String format, TimeZone tz) {
		SimpleDateFormat formatter = FORMATTER_CACHE.get(format);
		formatter.setTimeZone(tz);
		Date date = new Date(unixtime * 1000);
		try {
			return formatter.format(date);
		} catch (Exception e) {
			LOG.error("Exception when formatting.", e);
			return null;
		}
	}
9213
public static Time parseTime(final String date, final String format, final TimeZone timeZone) {
        if (N.isNullOrEmpty(date) || (date.length() == 4 && "null".equalsIgnoreCase(date))) {
            return null;
        }

        return createTime(parse(date, format, timeZone));
    }
729140
@Override
    public void setAsText(String text) {
        if (BeanUtils.isNull(text)) {
            setValue(null);
            return;
        }
        ParseException pe = null;

        for (int i = 0; i < formats.length; i++) {
            try {
                // try to parse the date
                DateFormat df = formats[i];
                Date date = df.parse(text);

                // store the date in both forms
                this.text = text;
                super.setValue(date);

                // done
                return;
            } catch (ParseException e) {
                // remember the last seen exception
                pe = e;
            }
        }
        // couldn't parse
        throw new IllegalArgumentException("Failed to parse to Date!", pe);
    }
1018457
public static String toLongFormatFromDate(Date date) {
    if (date == null) {
      return null;
    }

    return strategy.formatFor(FACEBOOK_LONG_DATE_FORMAT_WITHOUT_TIMEZONE).format(date);
  }
24618
@FromString
    public static DateMidnight parse(String str) {
        return parse(str, ISODateTimeFormat.dateTimeParser().withOffsetParsed());
    }
1368771
private String long2string(Long value, DateTimeFormat fmt) {
        // for html5 inputs, use "" for no value
        if (value == null) return "";
        Date date = UTCDateBox.utc2date(value);
        return date != null ? fmt.format(date) : null;
    }
106840
@CheckForNull
  public static Date parseDateOrDateTime(@Nullable String stringDate) {
    if (stringDate == null) {
      return null;
    }

    OffsetDateTime odt = parseOffsetDateTimeQuietly(stringDate);
    if (odt != null) {
      return Date.from(odt.toInstant());
    }

    LocalDate ld = parseLocalDateQuietly(stringDate);
    checkArgument(ld != null, "Date '%s' cannot be parsed as either a date or date+time", stringDate);

    return Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant());
  }
1120882
protected Date parseDate(final String dateString) {
		Date date = null;
		if (dateString != null) {
			try {
				final SimpleDateFormat dateFormat = new SimpleDateFormat(FREESOUND_DATE_FORMAT);
				dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

				date = dateFormat.parse(dateString);
			} catch (final ParseException e) {
				// TODO Log a warning
			}
		}

		return date;
	}
1179344
public static final Long date2utc(Date date) {

        // use null for a null date
        if (date == null) return null;
        
        long time = date.getTime();
        
        // remove the timezone offset        
        time -= timezoneOffsetMillis(date);
        
        return time;
    }