Java 时间戳格式化

package com.app.main.utils; import java.text.SimpleDateFormat; import java.util.Date; /** * Created with IDEA * author:Dingsheng Huang * Date:2019/6/29 * Time:下午6:47 */ public class DateTimeUtils {/** * 时间戳按指定格式转化为日期(String) * @param timestamp * @param pattern * @return */ public static String convertTimestamp2Date(Long timestamp, String pattern) {SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); return simpleDateFormat.format(new Date(timestamp)); }public static void main(String[] args) {Long timestamp = System.currentTimeMillis(); String pattern = "yyyy-MM-dd HH:mm:ss"; System.out.println(convertTimestamp2Date(timestamp, pattern)); }}

output:
【Java 时间戳格式化】Java 时间戳格式化
文章图片

    推荐阅读