Long second = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")); //获取毫秒数 Long milliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();

unix时间戳转LocalDateTime

long timestamp = System.currentTimeMillis();
LocalDateTime localDateTime = Instant.ofEpochMilli(timestamp).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();

Date转String:

Date d1 = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str = format.format(d1);

String转date

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//注意月份是MM
Date date = simpleDateFormat.parse("2019-09-02");
System.out.println(date);

LocalDateTime 转 String

DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());

String 转 LocalDateTime

String dateStr = "2019-10-28 12:03:15";
DateTimeFormatter localDateTimeFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime date = LocalDateTime.parse(dateStr, localDateTimeFormat);

 Date转LocalDateTime

LocalDateTime localDateTime = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();

LocalDateTime转Date

Date date = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
                    Date转String:Date d1 = new Date();SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String str = format.format(d1);LocalDateTime 转 StringDateTimeFormatter.ofPattern("yyyy-...
GMT 和UTC 时区是一样的,但是Date 对象是无法满足我们这个地域时区的格式,因此可以使用
localDate 或者localTime,localDateTime
localDate 包含日期设置,
localTime 包含时间设置,
localDateTime 包含日期和时间
JAVA通用时间工具类(Date 字符串LocalDateTime 字符串;timestamp 字符串字符串Date;获取当天剩余秒数)
@Test public void testJava8DateFormat() { DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDa...
import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.Date; public class DateUtils { public static void main(String[] args) {
程序开发中,经常拿到字符串类型的时间,需要将他们转化LocalDateTime时间,有时还需要获取13位的时间戳 public static void main(String[] args) { String gpsTime= "2022-03-19 17:37:38.222"; DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); System.out.println(String.va
开发当中经常时间换非常常见,最近的项目当中使用了LocalDateTime,特此记录下LocalDateTime的常用换。 LocalDateTime时间戳互 * 获取到毫秒级时间戳 * @param localDateTime 具体时间 * @return long 毫秒级时间戳 public static long toEpochMilli(LocalDateTime localDateTime){ retur
//LocalDateTime时间戳 //获取秒数 long second = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")); System.out.println(second); //获取毫秒数 ```javascript // 假设字符串时间为 '2022-03-01 10:30:00' const timestamp = new Date('2022-03-01 10:30:00').getTime(); console.log(timestamp); // 输出:1646127000000 这里使用了Date对象的getTime()方法来获取时间戳,它返回从1970年1月1日午夜(UTC)开始计算的毫秒数。注意,如果字符串时间格式不正确,或者字符串中包含的时间不符合当前时区的格式,将会导致换失败。 另外,如果要在Vue中使用时间戳,可以在模板中使用过滤器或计算属性来将时间换为可读格式。例如,可以使用以下过滤器将时间换为年月日格式: ```javascript Vue.filter('formatDate', function(timestamp) { const date = new Date(timestamp); const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); return `${year}-${month}-${day}`; 然后在模板中使用: ```html <p>{{ timestamp | formatDate }}</p> 其中,timestamp为时间戳。
maven发布deploy时repository element was not specified in the POM inside distributionManagement element 66479