title: Better way to convert a string field into timestamp in Spark
body: <p>I have a CSV in which a field is datetime in a specific format. I cannot import it directly in my Dataframe because it needs to be a timestamp. So I import it as string and convert it into a <code>Timestamp</code> like this</p>
  
  <pre><code>import java.sql.Timestamp
  import java.text.SimpleDateFormat
  import java.util.Date
  import org.apache.spark.sql.Row
  
  def getTimestamp(x:Any) : Timestamp = {
      val format = new SimpleDateFormat("MM/dd/yyyy' 'HH:mm:ss")
      if (x.toString() == "") 
      return null
      else {
          val d = format.parse(x.toString());
          val t = new Timestamp(d.getTime());
          return t
      }
  }
  
  def convert(row : Row) : Row = {
      val d1 = getTimestamp(row(3))
      return Row(row(0),row(1),row(2),d1)
  }
  </code></pre>
  
  <p>Is there a better, more concise way to do this, with the Dataframe API or spark-sql? The above method requires the creation of an RDD and to give the schema for the Dataframe again.</p>