Search code examples
intellij-idea

Replace all dates with new date format intelij


Is there some way to automatically replace format of date strings.

Example I have:

"2022-09-25T16:00:00.000Z" want to replace with "2022-09-25T18:00:00+0200"


Solution

  • Ok one solution is to use regex for find:

    ([0-9]{4}-[0-9]{2}-[0-9]{2}T.*?)00(:[0-9]{2}:[0:9]{2}.*?).000Z
    

    and for replace :

    $102$3+0200
    

    where

    • $1 is group 1 till T
    • 02 is the hour replacement for 00 (have to do this manually for all 24 hours)
    • $2 is the group selection after hour till the .
    • +0200 as a replacement for .000Z