Groovy String to Date

后端 未结 7 1962
花落未央
花落未央 2020-12-02 11:45

I am coding this with Groovy

I am currently trying to convert a string that I have to a date without having to do anything too tedious.

String theD         


        
7条回答
  •  自闭症患者
    2020-12-02 12:22

    I think the best easy way in this case is to use parseToStringDate which is part of GDK (Groovy JDK enhancements):

    Parse a String matching the pattern EEE MMM dd HH:mm:ss zzz yyyy containing US-locale-constants only (e.g. Sat for Saturdays). Such a string is generated by the toString method of Date

    Example:

    println(Date.parseToStringDate("Tue Aug 10 16:02:43 PST 2010").format('MM-dd-yyyy'))
    

提交回复
热议问题