How to convert LocalDate and Timestamp

To convert LocalDate and Timestamp, put LocalDateTime in between.

--Reference - Timestamp (Java Platform SE 8) - LocalDate (Java Platform SE 8)

How to convert LocalDate to Timestamp

/**
 *Get the current date and time with TimeStamp.
 * @return Current date and time.
 */
public Timestamp getTimestamp() {
    //Current date and time with LocalDate.
    var localDate = LocalDate.now();
    //Create LocalDateTime at the start of the date.
    var localDateTime = localDate.atStartOfDay();
    //Same date as LocalDateTime/Get Timestamp with time value.
    var timestamp = Timestamp.valueOf(localDateTime);
    return timestamp;
}

How to convert Timestamp to LocalDate

/**
 *Get the current date with LocalDate.
 * @return current date.
 */
public LocalDate getLocalDate() {
    //Current date and time in Timestamp.
    var timestamp = new Timestamp(new Date().getTime());
    //Convert Timestamp to LocalDateTime
    var localDateTime = timestamp.toLocalDateTime();
    //This date/Get LocalDate part of time
    var localDate = localDateTime.toLocalDate();
    return localDate;
}

Recommended Posts

How to convert LocalDate and Timestamp
How to convert java.util.Date, java.sql.Date, LocalDate, ZonedDateTime
[Convenient to remember !!!] How to convert from LocalDate type to character string and from character string to LocalDate type
[Ruby] How to convert from lowercase to uppercase and from uppercase to lowercase
Ruby How to convert between uppercase and lowercase
Convert String type to Timestamp type
How to convert Java radix
How to convert A to a and a to A using AND and OR in Java
How to use StringBurrer and Arrays.toString.
How to use EventBus3 and ThreadMode
How to convert erb file to haml
How to call classes and methods
How to use equality and equality (how to use equals)
How to connect Heroku and Sequel
[Java] How to convert from String to Path type and get the path
[Rails] How to convert from erb to haml
[Java] How to calculate age using LocalDate
[Core ML] How to convert YOLO v3 to Core ML
[Java] How to output and write files!
How to set up and use kapt
How to build SquashTM and how to support Japanese
How to find the tens and ones
[Easy] How to upgrade Ruby and bundler
How to use substring and substr methods
Note: [Docker] How to start and stop
How to write and explain Dockerfile, docker-compose
How to use @Builder and @NoArgsConstructor together
Convert JSON to TSV and TSV to JSON with Ruby
How to deploy
JDBC promises and examples of how to write
[Ruby] How to convert CSV file to Yaml (Yml)
[Java] How to use FileReader class and BufferedReader class
How to execute and mock methods using JUnit
[Android] How to convert a character string to resourceId
[Java] How to get and output standard input
[Ruby] How to use gsub method and sub method
How to play audio and music using javascript
How to convert a solidity contract to a Java contract class
How to use Segmented Control and points to note
Git and GitHub ~ How to fix common errors ~
How to set up and operate jEnv (Mac)
How to use scope and pass processing (Jakarta)
How to get and study java SE8 Gold
How to build API with GraphQL and Rails
How to execute processing before and after docker-entrypoint.sh
How to find the total score and average score
[Rails] How to get success and error messages
How to build parquet-tools and merge Parquet files
Rails scope anti-patterns and how to eliminate them
How to access Java Private methods and fields
[Rails] How to convert UC time display to Japanese time display
[Java] How to use Calendar class and Date class
How to convert a value of a different type and assign it to another variable
<java> Read Zip file and convert directly to string
How to develop OpenSPIFe
Convert Java enum enums and JSON to and from Jackson
How to call AmazonSQSAsync
How to use Map
How to write Rails
How to use rbenv
How to use letter_opener_web