Java時間変換文字列からタイムスタンプへ

タイムスタンプtime = new Timestamp(new SimpleDateFormat(“ yyyy-MM-dd”)。parse(“ 2021-02-19”)。getTime());

//数据库时间戳转换
public static String dealDateFormat(String oldDate) {
    Date date1 = null;
    DateFormat df2 = null;
    try {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        Date date = df.parse(oldDate);
        SimpleDateFormat df1 = new SimpleDateFormat ("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
        date1 = df1.parse(date.toString());
        df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    } catch (ParseException e) {

        e.printStackTrace();
    }
    return df2.format(date1);
}

おすすめ

転載: blog.csdn.net/qq_34117294/article/details/113863759