`
zysnba
  • 浏览: 187532 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

LocalDateTimeToString

 
阅读更多


/**
     * LocalDateTimeToString
     * @param date
     * @return
     */
    public static String LocalDateTimeToString(LocalDateTime date) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime time = date;
        String localTime = df.format(time);
        return localTime;
    }
    /**
     * StringToLocalDateTime
     * @param str
     * @return
     */
    public static LocalDateTime StringToLocalDateTime(String str) {
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDateTime date = LocalDateTime.parse(str, fmt);
        System.out.println("StringToLocalDate:"+date);
        return date;
    }
    /**
     * LocalDateToString
     * @param date
     * @return
     */
    public static String LocalDateToString(LocalDate date) {
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String dateStr = date.format(fmt);
        System.out.println("LocalDate转String:"+dateStr);
        return dateStr;
    }
    /**
     * StringToLocalDate
     * @param str
     * @return
     */
    public static LocalDate StringToLocalDate(String str) {
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate date = LocalDate.parse(str, fmt);
        System.out.println("StringToLocalDate:"+date);
        return date;
    }




如果对你有帮助请给小弟打赏下,祝你成功。



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics