src/main/java/com/zandero/utils/InstantTimeUtils.java
public static Instant getTimestamp(String value, DateTimeFormatter... formats) {

		Assert.notNull(formats, "Missing date time formats");
		Assert.isTrue(formats.length > 0, "Missing date time formats");

		if (StringUtils.isNullOrEmptyTrimmed(value)) {
			return null;
		}

		// OK check if we have 6 digit milliseconds ... if so truncate
		if (value.matches(".*\\.\\d{6}.*")) {
			// remove 3 milliseconds places
			int index = value.indexOf(".");
			value = value.substring(0, index + 4) + value.substring(index + 7);
		}

		// Go over all formats ... and if success return value
		for (DateTimeFormatter format : formats) {

			try {
				TemporalAccessor date = format.parse(value);
				return Instant.from(date);
			}
			catch (DateTimeParseException e) {
				// try next one ...
			}
		}

		return null;
	}
public static Instant getTimestamp(String value, DateTimeFormatter... formats) {

		Assert.notNull(formats, "Missing date time formats");
		Assert.isTrue(formats.length > 0, "Missing date time formats");

		if (StringUtils.isNullOrEmptyTrimmed(value)) {
			return null;
		}

		// OK check if we have 6 digit milliseconds ... if so truncate
		if (value.matches(".*\\.\\d{6}.*")) {
			// remove 3 milliseconds places
			int index = value.indexOf(".");
			value = value.substring(0, index + 4) + value.substring(index + 7);
		}

		// Go over all formats ... and if success return value
		for (DateTimeFormatter format : formats) {

			try {
				TemporalAccessor date = format.parse(value);
				return Instant.from(date);
			}
			catch (DateTimeParseException e) {
				// try next one ...
			}
		}

		return null;
	}
public static Instant getTimestamp ( String value , DateTimeFormatter ... formats ) { Assert . notNull ( formats , "Missing date time formats" ) ; Assert . isTrue ( formats . length > 0 , "Missing date time formats" ) ; if ( StringUtils . isNullOrEmptyTrimmed ( value ) ) { return null ; } // OK check if we have 6 digit milliseconds ... if so truncate if ( value . matches ( ".*\\.\\d{6}.*" ) ) { // remove 3 milliseconds places int index = value . indexOf ( "." ) ; value = value . substring ( 0 , index + 4 ) + value . substring ( index + 7 ) ; } // Go over all formats ... and if success return value for ( DateTimeFormatter format : formats ) { try { TemporalAccessor date = format . parse ( value ) ; return Instant . from ( date ) ; } catch ( DateTimeParseException e ) { // try next one ... } } return null ; }
Convert any given timestamp string to long
Note that in case conversion fails to produce a result a 0 timestamp is returned!

@param value   to be converted
@param formats list of formats to try out
@return time stamp or 0 if conversion failed
Convert any given timestamp string to long Note that in case conversion fails to produce a result a 0 timestamp is returned!