I am not sure if you want the code for Java, Hive or Pig. I am sharing the code for Java:
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
//class and the remaining code
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
Date parsedDate = dateFormat.parse(yourString);
Timestamp timestamp = new java.sql.Timestamp(parsedDate.getTime());