我在java jsp servlet代码中遇到异常我收到了标题中提到的错误 我从下面提到的stackoverflow链接尝试了解决方案,但没有用..
我的问题是将空值输入到mysql数据库中..我已经被困了两天了..
Java : Cannot format given Object as a Date
Error C2440 'initializing': cannot convert from 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' to 'PeerNet::NetPacket *' PeerNet \vc\include\xmemory0 737
错误日志:
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SetDate
{
public static java.util.Date set(String s,String f)
{
java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat(f);
java.util.Date date=null;
try
{
date=sdf.parse(s);
}
catch (ParseException ex)
{
Logger.getLogger(SetDate.class.getName()).log(Level.SEVERE, null, ex);
}
return date;
}
public static String format(Object time,String f) throws ParseException
{
SimpleDateFormat sdf=new SimpleDateFormat(f);
System.out.println("Date:- " +sdf.format(time));
return sdf.format(time);
}
}
答案 0 :(得分:1)
更改:
public static String format(Object time,String f) throws ParseException
{
SimpleDateFormat sdf=new SimpleDateFormat(f);
System.out.println("Date:- " +sdf.format(time));
return sdf.format(time);
}
为:
public static String format(Object time,String f) throws ParseException
{
if (time == null)
rteurn null;
SimpleDateFormat sdf=new SimpleDateFormat(f);
System.out.println("Date:- " +sdf.format(time));
return sdf.format(time);
}