Converts a String to the given timezone.

@param date      Date to format
@param zoneId    Zone id to convert from sherdog's time
@param formatter Formatter for exotic date format
@return the converted zonedatetime
557687
static ZonedDateTime getDateFromStringToZoneId(String date, ZoneId zoneId, DateTimeFormatter formatter) throws DateTimeParseException {
        try {
            //noticed that date not parsed with non-US locale. For me this fix is helpful
            LocalDate localDate = LocalDate.parse(date, formatter);
            ZonedDateTime usDate = localDate.atStartOfDay(zoneId);
            return usDate.withZoneSameInstant(zoneId);
        } catch (Exception e) {
            //In case the parsing fail, we try without time
            try {
                ZonedDateTime usDate = LocalDate.parse(date, formatter).atStartOfDay(ZoneId.of(Constants.SHERDOG_TIME_ZONE));
                return usDate.withZoneSameInstant(zoneId);
            } catch (DateTimeParseException e2) {
                return null;
            }
        }
    }
1293014
public static String toDateString(final Date date) {

        String result;
        if (date == null) {
            result = "";
        } else {
            result = Z_DATE_FORMAT.format(date);
        }
        return result;
    }
3991
public static String formatTime (Date date)
    {
        return (date == null) ? "" : _tfmt.format(date).toLowerCase();
    }
1246388
private static String formatUTCDateAsLocalDateTime(Date javaDate) {
    // Now back from start of day in UTC to LocalDateTime to express that we don't know the
    // timezone.
    LocalDateTime localDateTime = javaDate.toInstant().atZone(UTC).toLocalDateTime();
    // And format to string
    return localDateTime.toString();
  }
67581
public static String formatDate(Instant d) {
    return d.atZone(ZoneId.systemDefault()).toLocalDate().toString();
  }
157893
public static Date parseAWSDate(String date) {
		if (date == null) {
			return null;
		}
		return TIME_FORMATTER.parseDateTime(date).toDate();
	}
958205
private static String formatDate(Date date) {

        String dateStr = dateFormat.format(date);
        // insert colon into timezone
        return dateStr.substring(0, 22) + ":" + dateStr.substring(22);
    }
89357
@Transformer(requireTemplate = true)
    public static String format(Date date) {
        return format(date, null, null, null);
    }
101863
public static DateValue convert(ICalDate date, TimeZone timezone) {
		Calendar c = Calendar.getInstance(timezone);
		c.setTime(date);

		/*
		 * Do not create a "DateValueImpl" object if "date.hasTime() == false".
		 * This interferes with any recurrence iterators the object is passed
		 * into.
		 * 
		 * See: https://github.com/mangstadt/biweekly/issues/47
		 */

		//@formatter:off
		return new DateTimeValueImpl(
			c.get(Calendar.YEAR),
			c.get(Calendar.MONTH)+1,
			c.get(Calendar.DATE),
			c.get(Calendar.HOUR_OF_DAY),
			c.get(Calendar.MINUTE),
			c.get(Calendar.SECOND)
		);
		//@formatter:on
	}
690945
public static String format(Date date) {
        String format = LOCAL_DATE_FORMAT.format(date);
        // Java 6 does not have a convenient way of having the colon in the timezone offset
        return format.substring(0,22) + ":" + format.substring(22);
    }
684746
public static String getTime(long epochTimestamp, String timeFormat,
            ZoneId zoneId) {
        return getTime(epochTimestamp, getDateTimeFormatter(timeFormat),
                zoneId);
    }
1334399
public String timeToString(java.util.Date time, boolean withTimeZone) {
    Calendar cal = null;
    if (withTimeZone) {
      cal = calendarWithUserTz;
      cal.setTimeZone(timeZoneProvider.get());
    }
    if (time instanceof Timestamp) {
      return toString(cal, (Timestamp) time, withTimeZone);
    }
    if (time instanceof Time) {
      return toString(cal, (Time) time, withTimeZone);
    }
    return toString(cal, (Date) time, withTimeZone);
  }
284686
public static String getDateString(String format, Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
1275898
public static String changeFormatAndTimeZoneToOffsetDateTime(
            String dateFormat, String zoneOffsetId, String dateString) {
        return JMOptional.getOptional(zoneOffsetId)
                .map(id -> getOffsetDateTime(changeTimestampToLong
                        (dateFormat, dateString, id)).toString())
                .orElseGet(() -> changeFormatAndTimeZoneToOffsetDateTime(
                        dateFormat, dateString));
    }
620210
public static Timestamp parseTimestamp(final String date, final String format, final TimeZone timeZone) {
        if (N.isNullOrEmpty(date) || (date.length() == 4 && "null".equalsIgnoreCase(date))) {
            return null;
        }

        return createTimestamp(parse(date, format, timeZone));
    }
1324789
public static String format(final ZonedDateTime self, FormatStyle dateTimeStyle) {
        return self.format(DateTimeFormatter.ofLocalizedDateTime(dateTimeStyle));
    }
928768
public static String format(Date date, DateFormat format) {
		if (null == format || null == date) {
			return null;
		}
		return format.format(date);
	}