當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalDateTime.get方法代碼示例

本文整理匯總了Java中java.time.LocalDateTime.get方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDateTime.get方法的具體用法?Java LocalDateTime.get怎麽用?Java LocalDateTime.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.LocalDateTime的用法示例。


在下文中一共展示了LocalDateTime.get方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setDateTimeAt

import java.time.LocalDateTime; //導入方法依賴的package包/類
public static void setDateTimeAt(byte[] buffer, int pos, LocalDateTime dateTime) {
    int year, month, day, hour, min, sec;
    year = dateTime.get(ChronoField.YEAR);
    month = dateTime.get(ChronoField.MONTH_OF_YEAR);
    day = dateTime.get(ChronoField.DAY_OF_MONTH);
    hour = dateTime.get(ChronoField.HOUR_OF_DAY);
    min = dateTime.get(ChronoField.MINUTE_OF_HOUR);
    sec = dateTime.get(ChronoField.SECOND_OF_MINUTE);
    // milli = dateTime.get(ChronoField.MILLI_OF_SECOND);
    // // First two digits of miliseconds
    // int msecH = milli / 10;
    // // Last digit of miliseconds
    // int msecL = milli % 10;

    if (year > 1999) {
        year -= 2000;
    }
    buffer[pos] = byteToBCD(year);
    buffer[pos + 1] = byteToBCD(month);
    buffer[pos + 2] = byteToBCD(day);
    buffer[pos + 3] = byteToBCD(hour);
    buffer[pos + 4] = byteToBCD(min);
    buffer[pos + 5] = byteToBCD(sec);
    buffer[pos + 6] = byteToBCD(0);
    buffer[pos + 7] = byteToBCD(0);
}
 
開發者ID:comtel2000,項目名稱:mokka7,代碼行數:27,代碼來源:S7.java

示例2: getDateRelativeToToday

import java.time.LocalDateTime; //導入方法依賴的package包/類
private LocalDateTime getDateRelativeToToday(ChronoField field, int buffer) {
    LocalDateTime date = LocalDateTime.now();
    // want a date with a buffer either side of it and also not including the date itself
    int gap = 2 * buffer + 1;
    int max = (int)field.range().getSmallestMaximum();
    int rand = getRandomInt(1, max - gap);
    int value = rand >= date.get(field) - buffer ? rand + gap : rand;
    LocalDateTime relativeDate = date.with(field, value);

    // Adding logging to help with some spurious errors...
    log.info("Date: " + date + " rand: " + rand + " value: " + value + " Picked date: " + relativeDate);

    return relativeDate;
}
 
開發者ID:NHS-digital-website,項目名稱:hippo,代碼行數:15,代碼來源:CmsSteps.java


注:本文中的java.time.LocalDateTime.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。