use of java.time.ZoneId in project faceRecognizeSample_JAVA by eGroupIT.
the class DateUtil method calculate.
/**
* Calculate the date from now
*
* @author eGroupAI
*
* @param formate
* @param category
* @param formula
* @param digital
* @param calendar_
* @param zone
* @return
*/
public String calculate(Formate formate, Category category, Formula formula, Long digital, Calendar_ calendar_, Zone zone) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formate.getValue());
final ZoneId zoneId = ZoneId.of(zone.getValue());
final LocalDateTime localDateTime = LocalDateTime.now(zoneId);
final ZonedDateTime zonedDateTime = ZonedDateTime.now(zoneId);
boolean isLocalDateTime = isLocalDateTime(calendar_, formate);
String dateString = "";
switch(category.getValue()) {
case "Seconds":
dateString = caculateSeconds(localDateTime, zonedDateTime, formatter, formula, digital, isLocalDateTime, zone);
break;
case "Minutes":
dateString = caculateMinutes(localDateTime, zonedDateTime, formatter, formula, digital, isLocalDateTime, zone);
break;
case "Hours":
dateString = caculateHours(localDateTime, zonedDateTime, formatter, formula, digital, isLocalDateTime, zone);
break;
case "Days":
dateString = caculateDays(localDateTime, zonedDateTime, formatter, formula, digital, isLocalDateTime, zone);
break;
case "Months":
dateString = caculateMonths(localDateTime, zonedDateTime, formatter, formula, digital, isLocalDateTime, zone);
break;
case "Years":
dateString = caculateYears(localDateTime, zonedDateTime, formatter, formula, digital, isLocalDateTime, zone);
break;
default:
break;
}
if (!calendar_.getValue().equals(Calendar_.ANNO_DOMINI.getValue())) {
formatter = DateTimeFormatter.ofPattern(Formate.YMD_.getValue());
LocalDate localDate = LocalDate.parse(dateString, formatter);
dateString = getMinguo(calendar_, formate, localDate);
}
return dateString;
}
use of java.time.ZoneId in project faceRecognizeSample_JAVA by eGroupIT.
the class DateUtil method calculate.
/**
* Calculate the date
*
* @author eGroupAI
*
* @param startDateString
* @param formate
* @param category
* @param formula
* @param digital
* @param calendar_
* @param zone
* @return
*/
public String calculate(String startDateString, Formate formate, Category category, Formula formula, Long digital, Calendar_ calendar_, Zone zone) {
String dateString = null;
if (formate != null && category != null && formula != null && digital != null && calendar_ != null && attributeCheck.stringsNotNull(startDateString)) {
final ZoneId zoneId = ZoneId.of(zone.getValue());
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formate.getValue());
final LocalDateTime localDateTime = LocalDateTime.parse(startDateString, formatter);
final ZonedDateTime zonedDateTime = ZonedDateTime.now(zoneId);
boolean isLocalDateTime = isLocalDateTime(calendar_, formate);
switch(category.getValue()) {
case "Seconds":
dateString = caculateSeconds(localDateTime, zonedDateTime, formatter, formula, digital, isLocalDateTime, zone);
break;
case "Minutes":
dateString = caculateMinutes(localDateTime, zonedDateTime, formatter, formula, digital, isLocalDateTime, zone);
break;
case "Hours":
dateString = caculateHours(localDateTime, zonedDateTime, formatter, formula, digital, isLocalDateTime, zone);
break;
case "Days":
dateString = caculateDays(localDateTime, zonedDateTime, formatter, formula, digital, isLocalDateTime, zone);
break;
case "Months":
dateString = caculateMonths(localDateTime, zonedDateTime, formatter, formula, digital, isLocalDateTime, zone);
break;
case "Years":
dateString = caculateYears(localDateTime, zonedDateTime, formatter, formula, digital, isLocalDateTime, zone);
break;
default:
break;
}
if (!calendar_.getValue().equals(Calendar_.ANNO_DOMINI.getValue())) {
LocalDate localDate = LocalDate.parse(dateString, formatter);
dateString = getMinguo(calendar_, formate, localDate);
}
}
return dateString;
}
use of java.time.ZoneId in project faceRecognizeSample_JAVA by eGroupIT.
the class DateUtil method convertZone.
/**
* Convert date time from A zone to B zone
*
* @author eGroupAI
*
* @param formateInput
* @param formateOutput
* @param zone
* @param timestamp
* @return
*/
public String convertZone(Formate formateInput, String dateString, Formate formateOutput, Calendar_ calendar_, Zone zone) {
// Deprecate function name : getDateString_Transfer_zoneTime_fromTimestampUTCtoTimeZone
String newDateString = null;
if (formateInput != null && formateOutput != null && zone != null && calendar_ != null && attributeCheck.stringsNotNull(dateString) && isZonedDateTime(calendar_, formateInput)) {
final DateTimeFormatter formatterOuptut = DateTimeFormatter.ofPattern(formateOutput.getValue());
final ZoneId zoneId = ZoneId.of(zone.getValue());
ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateString);
ZonedDateTime finalZonedDateTime = zonedDateTime.withZoneSameInstant(zoneId);
newDateString = finalZonedDateTime.format(formatterOuptut);
}
return newDateString;
}
use of java.time.ZoneId in project hutool by looly.
the class TemporalAccessorConverter method parseFromCharSequence.
/**
* 通过反射从字符串转java.time中的对象
*
* @param value 字符串值
* @return 日期对象
*/
private TemporalAccessor parseFromCharSequence(CharSequence value) {
if (StrUtil.isBlank(value)) {
return null;
}
final Instant instant;
ZoneId zoneId;
if (null != this.format) {
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(this.format);
instant = formatter.parse(value, Instant::from);
zoneId = formatter.getZone();
} else {
final DateTime dateTime = DateUtil.parse(value);
instant = Objects.requireNonNull(dateTime).toInstant();
zoneId = dateTime.getZoneId();
}
return parseFromInstant(instant, zoneId);
}
use of java.time.ZoneId in project wicket by apache.
the class ZonedToLocalDateTimeModelTest method test.
@Test
public void test() {
ZoneId targetZone = ZoneId.of("UTC");
ZoneId clientZone = ZoneId.of("UTC+2");
IModel<ZonedDateTime> target = Model.of(ZonedDateTime.of(2000, 6, 1, 5, 0, 0, 0, targetZone));
ZonedToLocalDateTimeModel client = new ZonedToLocalDateTimeModel(target) {
@Override
protected ZoneId getTargetTimeZone() {
return targetZone;
}
@Override
protected ZoneId getClientTimeZone() {
return clientZone;
}
};
assertEquals(LocalDateTime.of(2000, 6, 1, 7, 0, 0, 0), client.getObject());
client.setObject(LocalDateTime.of(2000, 6, 1, 7, 30, 0, 0));
assertEquals(ZonedDateTime.of(2000, 6, 1, 5, 30, 0, 0, targetZone), target.getObject());
}
Aggregations