我有这个字符串,我想在日期表格中转换,如2013-06-06
"/Date(1370257470183+0530)/"
如果有人有想法,如何以编程方式执行此操作请帮助我
问候。
答案 0 :(得分:4)
public static void main(String[] args) {
String dateString = "/Date(1370257470183+0530)/";
String longString = dateString.substring(6, dateString.indexOf('+'));
String gmtString = dateString.substring(dateString.indexOf('+'), dateString.indexOf(')'));
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(TimeZone.getTimeZone(gmtString));
Date date = new Date(Long.parseLong(longString));
System.out.println(format.format(date));
}
SimpleDateFormat
答案 1 :(得分:3)
这是我编码的内容。但在此之前,您必须提取时区和毫秒时间,以便您可以创建对象。我认为你可以对字符串做一些字符串操作。
Date date = new Date(1370257470183l); // here is your time
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
formatter.setTimeZone(TimeZone.getTimeZone("GMT+0530")); // here is your timezone
String formattedDate = formatter.format(date);
System.out.println(formattedDate);
答案 2 :(得分:0)
您可以使用java.util.Date
课程,然后使用SimpleDateFormat
格式化日期。
Date date=new Date(millis);
参考:How to convert currentTimeMillis to a date in Java?
输入表示从纪元(1970年1月1日GMT)开始的时间(以毫秒为单位) 顺便说一句,您的输入代表2013年6月3日的日期
答案 3 :(得分:0)
首先,你必须在String中搜索数值,在这里链接: Search a String for Numerics
然后您想将数值转换为日期。为此,使用SimpleDateFormat“链接在这里:Oracle SimpleDateFormat