作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何将日期字符串转换为长字符串?我希望方法签名为 public static long Convert2(String dateStr,TimeZone fromTz, TimeZone toTz)
,其中 dateStr
的格式为 dd/MM/yyyy
.
最佳答案
public static long convert2(String dateStr,TimeZone fromTz, TimeZone toTz)
// Format in which you are getting the date
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
// Set the formater to the timezone in which you are getting the date
formatter.setTimeZone(fromTz);
// Converting the string date to date
Date date = formatter.parse(dateStr);
// Prints the date in the from time zone timezone. Not required as per the quest. Just for info
System.out.println(formatter.format(date));
// Set the formatter to use a different timezone
formatter.setTimeZone(toTz);
// Prints the date in the to time zone timezone. Not required as per the quest. Just for info
System.out.println(formatter.format(date));
// converting the new Timzone date to long as that is what is required
long longDate = date.getTime();
// return the long date.
return longDate;
关于java - 如何使用字符串 fromTZ 日期从时区 'fromTZ' 转换为 'toTZ'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10878027/
如何将日期字符串转换为长字符串?我希望方法签名为 public static long Convert2(String dateStr,TimeZone fromTz, TimeZone toTz)
我是一名优秀的程序员,十分优秀!