Java Timestamp - How can I create a Timestamp with the date 23/09/2007?

后端 未结 8 1782

How can I create a Timestamp with the date 23/09/2007?

相关标签:
8条回答
  • 2020-11-28 21:27

    What do you mean timestamp? If you mean milliseconds since the Unix epoch:

    GregorianCalendar cal = new GregorianCalendar(2007, 9 - 1, 23);
    long millis = cal.getTimeInMillis();
    

    If you want an actual java.sql.Timestamp object:

    Timestamp ts = new Timestamp(millis);
    
    0 讨论(0)
  • 2020-11-28 21:29

    According to the API the constructor which would accept year, month, and so on is deprecated. Instead you should use the Constructor which accepts a long. You could use a Calendar implementation to construct the date you want and access the time-representation as a long, for example with the getTimeInMillis method.

    0 讨论(0)
提交回复
热议问题