Java 8 introduced the java.time package which makes short work of creating and parsing timestamps.
To create a String representation of a timestamp we can use LocalDateTime.now().toString(), e.g.
String ts = LocalDateTime.now().toString()
To convert the string back into a time object we can use the parse method of LocalDateTime, e.g.