How to convert String to Date

    This article shows how to convert data from String to Date format using groovy.

    If you want to synchronize the text field into actual date format, you have to parse String to type Date.

    Below you can find a code example that can be used in both Incoming or Outgoing rules depending on your needs.

    1 import java.text.SimpleDateFormat;
    2 import java.text.DateFormat;
    3   
    4  def datePattern = "yyyy-MM-dd HH:mm:ss.S"; // define the desired date/time format
    5         DateFormat formatter = new SimpleDateFormat(datePattern);
    6         date = formatter.parse(dateString);
    • dateString  is the incoming data of type String. It could be a text field value.
    • datePattern should have the same format as you have in dateString
    • date  is a desired date with the type Date after transformation.