Java LocalDate Create getLocalDate(long timeInMillis)

Here you can find the source of getLocalDate(long timeInMillis)

Description

Get LocalDate for time in milli seconds.

License

Open Source License

Parameter

Parameter Description
timeInMillis Time in milli seconds

Return

LocalDate

Declaration

public static LocalDate getLocalDate(long timeInMillis) 

Method Source Code

//package com.java2s;
/*//  ww  w .  ja  va2  s  .com
 * Copyright (c) 2010,2012 Daniel Marell
 * All rights reserved.
 *
 * Permission is hereby granted, free  of charge, to any person obtaining
 * a  copy  of this  software  and  associated  documentation files  (the
 * "Software"), to  deal in  the Software without  restriction, including
 * without limitation  the rights to  use, copy, modify,  merge, publish,
 * distribute,  sublicense, and/or sell  copies of  the Software,  and to
 * permit persons to whom the Software  is furnished to do so, subject to
 * the following conditions:
 *
 * The  above  copyright  notice  and  this permission  notice  shall  be
 * included in all copies or substantial portions of the Software.
 *
 * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
 * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
 * MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;

public class Main {
    /**
     * Get LocalDate for time in milli seconds.
     *
     * @param timeInMillis Time in milli seconds
     * @return LocalDate
     */
    public static LocalDate getLocalDate(long timeInMillis) {
        return getLocalDateTime(timeInMillis).toLocalDate();
    }

    /**
     * Get LocalDate given Calendar.
     *
     * @param c Calendar
     * @return Local date
     */
    public static LocalDate getLocalDate(Calendar c) {
        return c.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }

    /**
     * Get LocalDateTime for time in milli seconds.
     *
     * @param timeInMillis Time in milli seconds
     * @return LocalDateTime
     */
    public static LocalDateTime getLocalDateTime(long timeInMillis) {
        return LocalDateTime.ofInstant(Instant.ofEpochMilli(timeInMillis),
                ZoneId.systemDefault());
    }
}

Related

  1. getCurrentLocalDate()
  2. getCurrentLocalDate()
  3. getCurrentLocalDate()
  4. getLocalDate(int year, int atDay)
  5. getLocalDate(java.util.Date date)
  6. toLocalDate(Calendar calendar)
  7. toLocalDate(final Date date)