Reputation: 894
When I post the datestring to server, the time always changes. How can I post the datestring in soap webservices.
<Validfrom>dateTime</Validfrom>
I convert the string to date object, it posted but the time changes.
plz help me anyone to me
private Date getDateObj(String dateInString) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date date = null;
try {
System.out.println(dateInString);
date = formatter.parse(dateInString);
System.out.println(date);
System.out.println(formatter.format(date));
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
Above code represents my date object and I posted data like:
request.addProperty(name.trim(),
getDateObj(value));
Upvotes: 1
Views: 909
Reputation: 5145
Actually you have to calculate server time like GMT because your location is India (according to stack overflow profile). So, you are in +5.30 GMT. That's why you are getting wrong time from server with India time. So, use my code that will give you GMT server time :)
Calendar cal = Calendar.getInstance();
Date currentLocalTime = cal.getTime();
DateFormat date = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
date.setTimeZone(TimeZone.getTimeZone("UTC-06"));
String localTime = date.format(currentLocalTime);
may thz will help u best of luck dude
Upvotes: 1