Groovy String to Date

后端 未结 7 1947
花落未央
花落未央 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:43

    The first argument to parse() is the expected format. You have to change that to Date.parse("E MMM dd H:m:s z yyyy", testDate) for it to work. (Note you don't need to create a new Date object, it's a static method)

    If you don't know in advance what format, you'll have to find a special parsing library for that. In Ruby there's a library called Chronic, but I'm not aware of a Groovy equivalent. Edit: There is a Java port of the library called jChronic, you might want to check it out.

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