美文网首页
java 字符串转日期格式

java 字符串转日期格式

作者: Luke_单车 | 来源:发表于2023-02-22 17:41 被阅读0次

    1. 将Java 字符串转化为Date

    2. 将Java类里面的Date转成String

    public static String getDateStrToTime(String time) {
            String timeBegin;
            //1. 字符串转化为Date
            SimpleDateFormat sdf = new SimpleDateFormat(dateFormatYMDofyyyy);
            Date date;
            try {
                date = sdf.parse(time);
    
                //2. Date转成String
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatYMDofChinese);
                timeBegin = simpleDateFormat.format(date);
                Log.d("getDateStr", "timeBegin: " + timeBegin);
            } catch (ParseException e) {
                e.printStackTrace();
                timeBegin = "";
            }
            return timeBegin;
    
        }
    
    
    * @param time 20220101
    * @return 2022年01月01日

    相关文章

      网友评论

          本文标题:java 字符串转日期格式

          本文链接:https://www.haomeiwen.com/subject/mwbakdtx.html