Example usage for java.time LocalDate atStartOfDay

List of usage examples for java.time LocalDate atStartOfDay

Introduction

In this page you can find the example usage for java.time LocalDate atStartOfDay.

Prototype

public LocalDateTime atStartOfDay() 

Source Link

Document

Combines this date with the time of midnight to create a LocalDateTime at the start of this date.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);

    LocalDateTime l = a.atStartOfDay();
    System.out.println(l);//from www  .  j a  v  a  2  s.  c  o m
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, 6, 21);
    System.out.println(localDate);

    LocalDateTime localTime1 = localDate.atStartOfDay();
    System.out.println(localTime1);

    LocalDateTime localTime2 = localDate.atTime(16, 21);
    System.out.println(localTime2);
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.of(2014, 2, 15); // 2014-02-15
    // ISO-8601 standard
    // the day-of-week to represent, from 1 (Monday) to 7 (Sunday)
    DayOfWeek dayOfWeek = date.getDayOfWeek();
    System.out.println(dayOfWeek); // SATURDAY

    System.out.println(DayOfWeek.of(3)); // WEDNESDAY

    System.out.println(dayOfWeek.getValue()); // 6
    System.out.println(dayOfWeek.name()); // SATURDAY

    System.out.println(date.getDayOfMonth()); // 15
    System.out.println(date.atStartOfDay()); // 2014-02-15 00:00

    System.out.println("DayOfWeek");
    dayOfWeek = DayOfWeek.FRIDAY;
    Locale locale = Locale.getDefault();
    System.out.println(dayOfWeek.getDisplayName(TextStyle.FULL, locale)); // Friday
    System.out.println(dayOfWeek.getDisplayName(TextStyle.NARROW, locale)); // F
    System.out.println(dayOfWeek.getDisplayName(TextStyle.SHORT, locale)); // Fri
}

From source file:Main.java

public static Date fromLocalDateInUTC(LocalDate date) {
    return Date.from(date.atStartOfDay().toInstant(ZoneOffset.UTC));
}

From source file:Main.java

public static Date fromLocalDate(LocalDate date) {
    Instant instant = date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
    return Date.from(instant);
}

From source file:Main.java

public static Timestamp toTimestamp(LocalDate localDate) {
    Date date = Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
    Timestamp timeStamp = new Timestamp(date.getTime());
    return timeStamp;
}

From source file:Main.java

public static Date fromLocalDateIn(LocalDate date, ZoneOffset timeZone) {
    return Date.from(date.atStartOfDay().toInstant(timeZone));
}

From source file:Main.java

/**
 * Checks if the type of the given date. Possible return values are standard
 * time, the date when to switch to daylight saving time (in Europe the last
 * Sunday in March), daylight saving time or the date when to switch back to
 * standard time (in Europe the last Sunday in October).
 * /*from  w  ww  . j  a  v a  2  s.  c o m*/
 * @return DayType
 * @param cal
 *          Date to check, cannot be null
 */
public static DayType getDSTType(LocalDate cal) {
    DayType status = DayType.DAYLIGHT_SAVING_TIME;
    LocalDateTime testDate = cal.atStartOfDay();
    ZonedDateTime zdt = ZonedDateTime.of(testDate, ZoneId.systemDefault());
    // Find type of day
    if (zdt.getZone().getRules().isDaylightSavings(testDate.toInstant(zdt.getOffset())))
        status = DayType.DAYLIGHT_SAVING_TIME;
    else
        status = DayType.STANDARD_TIME;
    // Check the day after
    testDate = testDate.plusDays(1);
    zdt = ZonedDateTime.of(testDate, ZoneId.systemDefault());
    // Find type of day after
    if (zdt.getZone().getRules().isDaylightSavings(testDate.toInstant(zdt.getOffset()))) {
        if (status != DayType.DAYLIGHT_SAVING_TIME)
            status = DayType.TO_DAYLIGHT_SAVING_TIME;
    } else {
        if (status == DayType.DAYLIGHT_SAVING_TIME)
            status = DayType.TO_STANDARD_TIME;
    }
    return status;
}

From source file:com.hengyi.japp.tools.DateTimeUtil.java

public static Date toDate(LocalDate localDate) {
    return localDate == null ? null : toDate(localDate.atStartOfDay());
}

From source file:com.hotelbeds.hotelapimodel.auto.util.AssignUtils.java

public static Date getDate(final LocalDate localDate) {
    Instant instant = localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
    return Date.from(instant);
}