本文整理了Java中java.time.ZoneId.systemDefault()
方法的一些代码示例,展示了ZoneId.systemDefault()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneId.systemDefault()
方法的具体详情如下:
包路径:java.time.ZoneId
类名称:ZoneId
方法名:systemDefault
[英]Gets the system default time-zone.
This queries TimeZone#getDefault() to find the default time-zone and converts it to a ZoneId. If the system default time-zone is changed, then the result of this method will also change.
[中]获取系统默认时区。
查询时区#getDefault()以查找默认时区并将其转换为ZoneId。如果更改了系统默认时区,则此方法的结果也将更改。
代码示例来源:origin: lets-blade/blade
/**
* format string time to unix time
*
* @param time string date
* @param pattern date format pattern
* @return return unix time
*/
public static int toUnix(String time, String pattern) {
LocalDateTime formatted = LocalDateTime.parse(time, DateTimeFormatter.ofPattern(pattern));
return (int) formatted.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond();
}
代码示例来源:origin: oblac/jodd
/**
* Converts local date to Date.
*/
public static Date toDate(final LocalDate localDate) {
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
/**
代码示例来源:origin: lets-blade/blade
public static String gmtDate(Date date) {
return GMT_FMT.format(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()).atZone(GMT_ZONE_ID));
}
代码示例来源:origin: lets-blade/blade
public Date format(String date, String pattern) {
DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern, Locale.US);
LocalDateTime formatted = LocalDateTime.parse(date, fmt);
Instant instant = formatted.atZone(ZoneId.systemDefault()).toInstant();
return Date.from(instant);
}
代码示例来源:origin: SonarSource/sonarqube
/**
* Return a date at the start of day.
*
* @param s string in format {@link #DATE_FORMAT}
* @throws SonarException when string cannot be parsed
*/
public static Date parseDate(String s) {
return Date.from(parseLocalDate(s).atStartOfDay(ZoneId.systemDefault()).toInstant());
}
代码示例来源:origin: lets-blade/blade
public static String gmtDate(Date date) {
return GMT_FMT.format(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()).atZone(GMT_ZONE_ID));
}
代码示例来源:origin: lets-blade/blade
public Date format(String date, String pattern) {
DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern, Locale.US);
LocalDateTime formatted = LocalDateTime.parse(date, fmt);
Instant instant = formatted.atZone(ZoneId.systemDefault()).toInstant();
return Date.from(instant);
}
代码示例来源:origin: SonarSource/sonarqube
@CheckForNull
private static Instant parseDate(String propertyValue) {
try {
LocalDate localDate = LocalDate.parse(propertyValue);
return localDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
} catch (DateTimeParseException e) {
boolean invalidDate = e.getCause() == null || e.getCause() == e || !e.getCause().getMessage().contains("Invalid date");
checkPeriodProperty(invalidDate, propertyValue, "Invalid date");
return null;
}
}
代码示例来源:origin: spring-projects/spring-loaded
public static String run() {
LocalDateTime time = LocalDateTime.now();
ZonedDateTime zdt = time.atZone(ZoneId.systemDefault());
return zdt.toString();
}
代码示例来源:origin: lets-blade/blade
/**
* format string time to unix time
*
* @param time string date
* @param pattern date format pattern
* @return return unix time
*/
public static int toUnix(String time, String pattern) {
LocalDateTime formatted = LocalDateTime.parse(time, DateTimeFormatter.ofPattern(pattern));
return (int) formatted.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond();
}
代码示例来源:origin: knowm/XChange
private static void raw(Exchange bfx) throws IOException {
/*
BitfinexTradeServiceRaw tradeService = (BitfinexTradeServiceRaw) bfx.getTradeService();
LimitOrder limitOrder = new LimitOrder.Builder(OrderType.BID, CurrencyPair.BTC_USD).limitPrice(new BigDecimal("481.69"))
.originalAmount(new BigDecimal("0.001")).build();
tradeService.placeBitfinexLimitOrder(limitOrder, BitfinexOrderType.LIMIT);
*/
BitfinexTradeServiceRaw tradeService = (BitfinexTradeServiceRaw) bfx.getTradeService();
Date tenDaysAgo =
Date.from(LocalDate.now().minusDays(10).atStartOfDay(ZoneId.systemDefault()).toInstant());
BitfinexFundingTradeResponse[] fundingTradeResponses =
tradeService.getBitfinexFundingHistory("USD", tenDaysAgo, 2000);
}
}
代码示例来源:origin: stackoverflow.com
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
public class DateUtils {
public static Date asDate(LocalDate localDate) {
return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
}
public static Date asDate(LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
public static LocalDate asLocalDate(Date date) {
return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate();
}
public static LocalDateTime asLocalDateTime(Date date) {
return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime();
}
}
代码示例来源:origin: oblac/jodd
/**
* Converts local date time to epoh milliseconds.
*/
public static long toMilliseconds(final LocalDateTime localDateTime) {
return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
代码示例来源:origin: SonarSource/sonarqube
/**
* Warning: may rely on default timezone!
*
* @return the datetime, {@code null} if stringDate is null
* @throws IllegalArgumentException if stringDate is not a correctly formed date or datetime
* @since 6.1
*/
@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());
}
代码示例来源:origin: scouter-project/scouter
private void setTimeAsYmd() {
ZoneId zoneId = ZoneId.systemDefault();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmm");
LocalDateTime startDateTime = LocalDateTime.parse(startYmdHm, formatter);
LocalDateTime endDateTime = LocalDateTime.parse(endYmdHm, formatter);
startTimeMillis = startDateTime.atZone(zoneId).toEpochSecond() * 1000L;
endTimeMillis = endDateTime.atZone(zoneId).toEpochSecond() * 1000L;
}
代码示例来源:origin: oblac/jodd
/**
* Converts local date time to Date.
*/
public static Date toDate(final LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
代码示例来源:origin: Graylog2/graylog2-server
final Date date;
if (value instanceof ZonedDateTime) {
date = Date.from(((ZonedDateTime) value).toInstant());
} else if (value instanceof OffsetDateTime) {
date = Date.from(((OffsetDateTime) value).toInstant());
} else if (value instanceof LocalDateTime) {
final LocalDateTime localDateTime = (LocalDateTime) value;
final ZoneId defaultZoneId = ZoneId.systemDefault();
final ZoneOffset offset = defaultZoneId.getRules().getOffset(localDateTime);
date = Date.from(localDateTime.toInstant(offset));
final LocalDate localDate = (LocalDate) value;
final LocalDateTime localDateTime = localDate.atStartOfDay();
final ZoneId defaultZoneId = ZoneId.systemDefault();
final ZoneOffset offset = defaultZoneId.getRules().getOffset(localDateTime);
date = Date.from(localDateTime.toInstant(offset));
代码示例来源:origin: scouter-project/scouter
private void setTimeAsYmd() {
ZoneId zoneId = ZoneId.systemDefault();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHH");
LocalDateTime startDateTime = LocalDateTime.parse(startYmd, formatter);
LocalDateTime endDateTime = LocalDateTime.parse(endYmd, formatter);
startYmdH = startDateTime.atZone(zoneId).toEpochSecond() * 1000L;
endYmdH = endDateTime.atZone(zoneId).toEpochSecond() * 1000L;
}
}
代码示例来源:origin: lets-blade/blade
public static Date toDateTime(String time, String pattern) {
LocalDateTime formatted = LocalDateTime.parse(time, DateTimeFormatter.ofPattern(pattern));
return Date.from(formatted.atZone(ZoneId.systemDefault()).toInstant());
}
代码示例来源:origin: hibernate/hibernate-orm
: ZoneId.systemDefault();
_airFrance.setName( "Paris-Amsterdam" );
_airFrance.setDuration( Long.valueOf( 10 ) );
_airFrance.setDepartureDate( Date.from(LocalDate.of( 2005, 06, 21 ).atStartOfDay(zoneId).toInstant()) );
_airFrance.setAlternativeDepartureDate( new GregorianCalendar( 2006, 02, 03, 10, 00 ) );
_airFrance.getAlternativeDepartureDate().setTimeZone( TimeZone.getTimeZone( "GMT" ) );
assertNotNull( copyAirFrance );
assertEquals(
Date.from(LocalDate.of( 2005, 06, 21 ).atStartOfDay(zoneId).toInstant()),
copyAirFrance.getDepartureDate()
);
内容来源于网络,如有侵权,请联系作者删除!