I have this String which I want to convert in Date form like 2013-06-06
"/Date(1370257470183+0530)/"
If anybody have Idea , How to do this programmatically please help me
Regards.
I have this String which I want to convert in Date form like 2013-06-06
"/Date(1370257470183+0530)/"
If anybody have Idea , How to do this programmatically please help me
Regards.
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
Here is what I coded. But before that you have to extract the timezone and the millisecond time so that you can create the Object. I think that you can do just doing some string operations upon the string.
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);
You may use java.util.Date
class and then use SimpleDateFormat
to format the Date.
Date date=new Date(millis);
Reference: How to convert currentTimeMillis to a date in Java?
The input represents time in milliseconds from epoch ( Jan 1, 1970 GMT) by the way your input represents a date of 3rd June 2013
First you will have to search the String for the numeric values, link here: Search a String for Numerics
Then you want to turn the numeric value into a date. For that use SimpleDateFormat" link here:Oracle SimpleDateFormat