我想要给定日期的时间戳。 使用此代码
public static String getTimestamp(String time)
{
DateFormat dfm = new SimpleDateFormat("dd-mm-yy hh:mm:ss");
long unixtime = 0;
dfm.setTimeZone(TimeZone.getTimeZone("GMT+5:30"));
try
{
unixtime = dfm.parse(time).getTime();
unixtime=unixtime/1000;
}
catch (ParseException e)
{
e.printStackTrace();
}
return ""+unixtime;
}
public static void main(String[] args)
{
System.out.println(getTimestamp("11-05-15 11:54:55"));
}
但是当我输入这个日期 11-05-15 11:54:55
然后程序返回我 1420957495 这个时间戳是 Jan (01) 的时间戳,但我想要 May(06)
请帮助我
最佳答案
用这个 DateFormat dfm = new SimpleDateFormat("dd-MM-yy hh:mm:ss");
大写MM代表月份,小写代表分钟
关于java - 使用 Java GMT+5 :30 获取时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30161344/