admin 管理员组

文章数量: 887053


2024年1月14日发(作者:eventhandler的使用)

import ateTime;public static void main(String[] args) { LocalDateTime today = (); n(today);}输出:2021-04-12T16:37:25.244获取当前时间(Timestamp类型)import amp;import DateFormat;public static void main(String[] args) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Timestamp timestamp = new Timestamp(tTimeMillis()); String now = (timestamp); n(now);}输出:2021-04-12 17:06:33Date类型 与 String类型转换import xception;import DateFormat;import ;public static void main(String[] args) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //Date转String Date date = new Date(); String now = (date); n(now); //String转Date Date now2 = ("2021-04-12 17:30:54"); n(now2);}输出:2021-04-12 16:55:59DateTime类型 转 String类型public static void main(String[] args) { DateTime dateTime = new DateTime(); String nowTime = ng("yyyy-MM-dd HH:mm:ss"); n(nowTime);}输出:2021-04-12 16:54:09

Date类型 转 Instant类型import t;import ;public static void main(String[] args) { Date date = new Date(); Instant instant = ant(); n(instant);}输出:2021-04-12 16:54:09DateTime类型 与 Calendar类型转换import ar;import ;public static void main(String[] args) { //Calendar转化为Date Calendar cal = tance(); Date date = e(); n(date); //Date转化为Calendar Date date2=new Date(); Calendar cal2 = tance(); e(date2); n(cal2);}输出:Mon Apr 12 17:27:11 CST 2021输

出:ianCalendar[time=02,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=aString类型 与 Instant类型转换

import t;import ateTime;import ;import meFormatter;import ;public static void main(String[] args) { //Instant转String DateTimeFormatter dtf = ern("yyyy-MM-dd HH:mm:ss"); Instant instant = (); ZoneId zoneId = Default(); LocalDateTime localDateTime = ant(instant, zoneId); String now = (localDateTime); n(now); //String转Instant String string = "2021-04-12T23:59:59.123Z"; DateTimeFormatter dtf2 = ern("yyyy-MM-dd'T'HH:mm:'Z'", ); LocalDateTime date = (string, dtf2); n(date);}输出:2021-04-12 17:01:33LocalDate类型 转换 Date类型import t;import ate;import ;import ;public static void main(String[] args) { LocalDate localDate = (); ZoneId zone = Default(); Instant instant = tOfDay().atZone(zone).toInstant(); Date date = (instant); n(date);}输出:Mon Apr 12 00:00:00 CST 2021


本文标签: 类型 时间 使用 作者 转换