Timestamp 和 SimpleDateFormat 的不同

xiabibo 发布于 2011/10/17 16:15
阅读 1K+
收藏 0
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  try {
   long a = 1L;

   long sdf1 = sdf.parse("2011-10-17 00:00:00").getTime();
   long sdf2 = sdf.parse("2011-10-18 00:00:00").getTime();

   long t1 = Timestamp.valueOf("2011-10-17 00:00:00.000").getTime();
   long t2 = Timestamp.valueOf("2011-10-17 23:59:59.999").getTime();

   if (a >= sdf1 && a < sdf2) {

    //范围1
  }
   
   if (a >= t1 && a <= t2) {

    //范围2
  }

}

范围1与范围2在何种情况下不相同呢?

加载中
返回顶部
顶部