的问题,同时从日期获取毫秒 [英] Problem while fetching Milliseconds from Date
问题描述
我在字符串格式的日期为 2010 11月25日
,我试图获取该日期的毫秒为单位,我有完成下面的code:
I have a date in string format as 25 November 2010
and i am trying to fetch the Milliseconds of that date, for that i have done the below code:
strDateSelcted = "25 November 2010" // Actually i am receiving date in this format
SimpleDateFormat curFormater = new SimpleDateFormat("dd MMM yyyy");
try {
Date dateObj = curFormater.parse(strDateSelcted);
insertEventtoCalendar(dateObj.getTime()); // Actually insert an event onto the native calendar
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但是,当我尝试运行应用程序,它创建插入日期的前一天它插入2010年11月26日事件的事件,即2010年把它插入事件于2010年11月25年11月24日和27 2010年11月,和一样的。
But, when i try to run the application,it creates an event a day before the date inserted, i.e. For 25 November 2010 it inserts event on 24 November 2010 and For 27 November 2010 it inserts event on 26 November 2010, and same.
所以,我在哪里犯了一个错误????请告诉我的方式做正确的
So where i am making a mistake???? pls show me way to do right
推荐答案
要设置的日期格式使用的时区:调用setTimeZone方法
例如
To set the timezone used by the date formatter: call the setTimeZone method e.g.
curFormater.setTimeZone(TimeZone.getTimeZone("UTC"));
这篇关于的问题,同时从日期获取毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!