Here you can find the source of getStringToTimestamp(String string)
Parameter | Description |
---|---|
string | string value to convert |
public static long getStringToTimestamp(String string)
//package com.java2s; //License from project: Apache License import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**/*from w w w .jav a2 s. c o m*/ * return unix timestamp of specified string value in format: yyyy-MM-dd HH:mm:ss * * @param string string value to convert * @return long value */ public static long getStringToTimestamp(String string) { try { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); ParsePosition parsePosition = new ParsePosition(0); Date date = simpleDateFormat.parse(string, parsePosition); return date.getTime(); } catch (Exception e) { return -1; } } }