how to retrieve day month and year from Timestamp(long format)

后端 未结 5 1033
再見小時候
再見小時候 2020-12-15 17:38

I need to retrieve day year and month from a timestamp object as long numbers:

public long getTimeStampDay()
    {

            String iDate = new SimpleDate         


        
5条回答
  •  再見小時候
    2020-12-15 18:17

    A little refreshment of this well-accepted thread that is a bit outdated by now.

    Back in the day, Java 8 introduced Date and Time API which makes extracting much cleaner.

    Let's assume that bornDate is instance of LocalDateTime.

    bornDate.getDayOfMonth(); // extracts day of month
    bornDate.getMonth();      // extracts month
    bornDate.getYear();       // extracts year
    

    Oracle reference: Java SE 8 Date and Time

提交回复
热议问题