java时间转时间戳

阅读更多
就一个破时间,也是转来转去。转你MLGB.也没看到有可用的工具类。
沙逼!!!!

一堆破逼转换,用来显示你的API设计的高级吗?

如果时间可以重来。绝不选择JAVA!



public class Test {

public static void main(String[] args) {



DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setLenient(false);
// 要转换字符串 str_test
Calendar calendar = Calendar.getInstance();
int month = calendar.get(Calendar.MONTH)+1;

String str_test = calendar.get(Calendar.YEAR) + "-" + month + "-"
+ calendar.get(Calendar.DAY_OF_MONTH);

try {
System.out.println(str_test);
// System.out.println(format.parse(str_test).getTime());
long newTime=format.parse(str_test).getTime();

Timestamp ts = new Timestamp(newTime);
System.out.println(newTime);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}



}

}

你可能感兴趣的:(java)