本文整理匯總了Java中java.time.LocalTime.ofSecondOfDay方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalTime.ofSecondOfDay方法的具體用法?Java LocalTime.ofSecondOfDay怎麽用?Java LocalTime.ofSecondOfDay使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.LocalTime
的用法示例。
在下文中一共展示了LocalTime.ofSecondOfDay方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readExternal
import java.time.LocalTime; //導入方法依賴的package包/類
/**
* Reads the state from the stream.
*
* @param in the input stream, not null
* @return the created object, not null
* @throws IOException if an error occurs
*/
static ZoneOffsetTransitionRule readExternal(DataInput in) throws IOException {
int data = in.readInt();
Month month = Month.of(data >>> 28);
int dom = ((data & (63 << 22)) >>> 22) - 32;
int dowByte = (data & (7 << 19)) >>> 19;
DayOfWeek dow = dowByte == 0 ? null : DayOfWeek.of(dowByte);
int timeByte = (data & (31 << 14)) >>> 14;
TimeDefinition defn = TimeDefinition.values()[(data & (3 << 12)) >>> 12];
int stdByte = (data & (255 << 4)) >>> 4;
int beforeByte = (data & (3 << 2)) >>> 2;
int afterByte = (data & 3);
LocalTime time = (timeByte == 31 ? LocalTime.ofSecondOfDay(in.readInt()) : LocalTime.of(timeByte % 24, 0));
ZoneOffset std = (stdByte == 255 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds((stdByte - 128) * 900));
ZoneOffset before = (beforeByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + beforeByte * 1800));
ZoneOffset after = (afterByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + afterByte * 1800));
return ZoneOffsetTransitionRule.of(month, dom, dow, time, timeByte == 24, defn, std, before, after);
}
示例2: main
import java.time.LocalTime; //導入方法依賴的package包/類
/**
* 程序執行入口.
*
* @param args 命令行參數
*/
public static void main(String[] args) {
LocalTime time = LocalTime.now();// |\longremark{獲取當前時間}|
System.out.println("Current Time=" + time);
LocalTime specificTime = LocalTime.of(12, 20, 25, 40); // |\longremark{根據給定時間創建時間對象}|
System.out.println("Specific Time of Day=" + specificTime);
LocalTime timeShanghai = LocalTime.now(ZoneId.of("Asia/Shanghai")); // |\longremark{根據給定時區創建時間對象}|
System.out.println("Current Time in CST=" + timeShanghai);
//Getting date from the base date i.e 01/01/1970
LocalTime specificSecondTime = LocalTime.ofSecondOfDay(10000);// |\longremark{獲得從1970-1-1開始計算的時間}|
System.out.println("10000th second time= " + specificSecondTime);
LocalTime one = LocalTime.parse("12:30:55"); //|\longremark{將字符串解析為LocalTime對象}|
LocalTime two = LocalTime.parse("13:02:15");
//LocalTime three = LocalTime.parse("2016-1-1 13:02:15"); // 格式錯誤
System.out.println("12:30:55 parsed to LocalDate = " + one);
System.out.println("12:30:55 < 13:02:15 ? " + one.isBefore(two));
System.out.println("12:30:55 < 12:30:55 ? " + one.isBefore(one));
System.out.println("13:02:15 > 12:30:55 ? " + two.isAfter(one));
}
示例3: factory_ofSecondOfDay_singletons
import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void factory_ofSecondOfDay_singletons() {
for (int i = 0; i < 24; i++) {
LocalTime test1 = LocalTime.ofSecondOfDay(i * 60L * 60L);
LocalTime test2 = LocalTime.of(i, 0);
assertSame(test1, test2);
}
}
示例4: second
import java.time.LocalTime; //導入方法依賴的package包/類
public static Time second(int seconds) {
LocalDate date = LocalDate.ofYearDay(0, asStartDays(seconds));
LocalTime time = LocalTime.ofSecondOfDay(asSecondsAtDay(seconds));
return new Time(LocalDateTime.of(date, time));
}
示例5: factory_ofSecondOfDay
import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void factory_ofSecondOfDay() {
LocalTime localTime = LocalTime.ofSecondOfDay(2 * 60 * 60 + 17 * 60 + 23);
check(localTime, 2, 17, 23, 0);
}
示例6: factory_ofSecondOfDay_tooLow
import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofSecondOfDay_tooLow() {
LocalTime.ofSecondOfDay(-1);
}
示例7: factory_ofSecondOfDay_tooHigh
import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofSecondOfDay_tooHigh() {
LocalTime.ofSecondOfDay(24 * 60 * 60);
}
示例8: getRandomTime
import java.time.LocalTime; //導入方法依賴的package包/類
/**
* Get the random time of day in seconds.
*
* @return the time in seconds
*/
public static final LocalTime getRandomTime() {
return LocalTime.ofSecondOfDay(getRandomInt(DAY_SECONDS));
}
示例9: getRandomTime
import java.time.LocalTime; //導入方法依賴的package包/類
/**
* Get the random time of day in seconds.
*
* @return the time in seconds
*/
public static final LocalTime getRandomTime() {
return LocalTime.ofSecondOfDay(getRandomInt(DAY_SECONDS));
}