源码如下

package data.xxx.util;

import java.util.Date;
import java.text.ParseException;
import com.ibm.icu.text.SimpleDateFormat;
import com.ibm.icu.util.TimeZone;

public class DateUtils {
	
	/**
	 * 字符串格式的日期转为对象格式的日期
	 * @param strDate 字符串格式日期 例如:2019-09-02 15:15:30870
	 * @param format 日期的模式匹配 例如:yyyy-MM-dd HH:mm:ssSSS
	 * @return 对象格式日期 例如:Mon Sep 02 15:15:30 CST 2019
	 * @throws ParseException
	 */
	public static Date strToDate(String strDate,String format) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Date date = sdf.parse(strDate);
		return date;
	}

	
}

正确的如下

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class DateUtils {
	
	/**
	 * 字符串格式的日期转为对象格式的日期
	 * @param strDate 字符串格式日期 例如:2019-09-02 15:15:30870
	 * @param format 日期的模式匹配 例如:yyyy-MM-dd HH:mm:ssSSS
	 * @return 对象格式日期 例如:Mon Sep 02 15:15:30 CST 2019
	 * @throws ParseException
	 */
	public static Date strToDate(String strDate,String format) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Date date = sdf.parse(strDate);
		return date;
	}

	
}

问题出现的原因:导包时自动导的包,导包错了

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐