jinlin
4 天以前 66f0597bf6a1e79540c6bc51dedf561c22f3bdb5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.example.server.progressTrack.service;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
 
public class StringToTimestampExample {
    public static void main(String[] args) {
        String dateString = "2022-01-01 ";
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd ");
        Date date = null;
        try {
            date = format.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Long timestamp=date.getTime();
        System.out.println("Timestamp: " + timestamp);
    }
}