I am having a hard time trying to make a web service client work. It is a XML RPC specification. I am using Apache WS XML-RPC library, which I find full of holes that causes problem due to Serialization. I have to send a Date parameter for the library to add the tags , however the web service expects it with the TZ, that means adding -0500 at the end of the Date object. If I dont send it as Date Object, it wont add the tags and it will fail. And when trying to do this:
DateFormat df = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ssZ");
String fecha = df.format(new Date());
Date date = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ssZ").parse(fecha);
And using parameter date, and it always sends it as
<dateTime.iso8601>20130517T20:30:33</dateTime.iso8601>
Can't find a way for it to send it as Date object in the format above but with the -0500 at the end. Any help would be appreciated.
Related
I have a web application where user can post the message to a restful API, so that that information can be saved in the database.
My problem when the data is sent from the UI, the date sent is "effStartDate":"2016-08-13" , but when i see the date value in the java code it is showing Fri Aug 12 20:00:00 EDT 2016.
I am using AngularJS,Spring and iBatis as the ORM tool. Attached are the screen shots with data sent from UI and what i see in the backend code.
can anyone help me with this?
You can add annotations to realize in the entity.
(Have to rely on JackJson`s jar)
and Then add in required fields
"#JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")"
You can treat the date as a string. Something like this
#JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
You can try this use date format from javascript code to send requests to a server by REST api.
For example:
effStartDate.toISOString();
The toISOString() method returns a string in simplified extended ISO format
From few days I am fighting with different Timezone issues of server and GWT client. but cannot get any success.
Scenario is Server is in UTC timezone let say Client A is in IST timezone.
When client select a date (with time) I pushed to server but date is automatically changed to server's timezone. I dig around this issue and I found multiple solutions like
create custom serializer (No idea how to do that can't found any proper example)
transfer date as a string to server and convert it to server timezone and store it. and when fetching data convert again from server's timezone to client local timezone. sounds good idea.
So my query is.
Any other solutions?
which is best way to manage this ?
any sample code or link?
Simply format the date in UTC format at client side and pass the date as string to the server and store the data in UTC format in database as well.
On the server side everything would be fine, since formatting the date would use the timezone of the server, which is what the date is stored in. On the client side, however, GWT will use the timezone of the client machine, and so there could be a discrepancy.
Sample code:
DateTimeFormat f = DateTimeFormat.getFormat("MMM dd yyyy");
TimeZoneConstants t = (TimeZoneConstants) GWT.create(TimeZoneConstants.class)
TimeZone est = TimeZone.createTimeZone(t.americaNewYork());
int offset = est.isDaylightTime(date) ? +240 : +300;
TimeZone tz = TimeZone.createTimeZone(offset);
String date = f.format(user.getBirthDate(), est);
There are a few other possible solutions, but one of these two might do the trick.
How do I get GWT DateTimeFormat to display using the server TimeZone, rather than the client's?
how to convert date in string variable to date variable..??
Date in database is in yyyy-MM-dd format..
im entering in dd-MM-yyyy format..and trying to convert it in db format so that i can use 'between' query.. code is below
<%String date1=(String)request.getAttribute("from");%>
<%String date2=(String)request.getAttribute("to");%>
<%String empcode=(String)request.getAttribute("occ");%>
<%SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd");%>
<%Date date = new Date(); %>
<%Date fromdate=formatter.parse(date1);%>
<%Date todate=formatter.parse(date2);%>
You're using getAttribute, but I suspect you wanted getParameter (if you're trying to get information submitted as part of a GET or POST request).
Here's what getAttribute works with:
Attributes can be set two ways. The servlet container may set attributes to make available custom information about a request. For example, for requests made using HTTPS, the attribute javax.servlet.request.X509Certificate can be used to retrieve information on the certificate of the client. Attributes can also be set programatically using setAttribute(java.lang.String, java.lang.Object). This allows information to be embedded into a request before a RequestDispatcher call.
Here's what getParameter works with:
Returns the value of a request parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.
Looking at the date formatting, you've mentioned two different formats in your question. If the date1 string looks like 2013-12-19, then that code will work. If it's 19-12-2013 then that code won't work because you've told SimpleDateFormat to use "yyyy-MM-dd" but you want "dd-MM-yyyy".
In both cases, the way to debug this is to look at what date1 and date2 contain. That would point the way toward how to fix it.
SimpleDateFormat formatter=new SimpleDateFormat("dd-MM-yyyy");
Date fromdate=formatter.parse(date1);
SimpleDateFormat formatter2=new SimpleDateFormat("yyyy-MM-dd");
String newDate1 = formatter2.format(fromdate);
newDate1 is now in format yyyy-MM-dd.
You can again create the date object with the new string
formatter2.parse(newDate1);
but not necessary I suppose
Please can any body help me I have been faced time related problem regarding client and server time display issue since 1 week.
Description: Actually server is located in Germany when client (example : india) try to send any message to his contacts it will show the message sending time is server time (means Germany time).But I should say local specific time.I user send any then I show message sending time like this.
public static String retrieveFullDateFromDateinAMPM ( Date date ) {
SimpleDateFormat sdf =
new SimpleDateFormat("dd/MM/yy hh:mm a", Locale.getDefault());
return sdf.format(date);
}
Here I send date value to my helper method retrieveFullDateFromDateinAMPM(Date date) and I will return the message sending time like this : return sdf.format(date); to the web page. But it shows server located time but I should need to show locale specific time. Please help me. Advanced Thanks.
First of all Date does not know anything about specific timezones. You need to call SimpleDateFormat#setTimeZone to set specific timezones.
Consider code like below setting IST (Indian Standard Time) timezone on your DateFormat instance:
DateFormat sdf = new SimpleDateFormat("dd/MM/yy hh:mm a", Locale.getDefault());
sdf.setTimeZone(TimeZone.getTimeZone("IST"));
// Will print the date-time in the IST timezone
System.out.println(sdf.format(date));
OR else format the data using current timezone of the system:
sdf.setTimeZone( TimeZone.getDefault() );
a server-side solution mandates that the server code knows about the location of the client. i assume that this information will be supplied somehow as a iso 2-letter code. the java api mandates that for the following solution to work the language must also be known. i assume that it can be derived from the country code or is expressly supplied as an iso 2-/3-letter code.
so a revised method might be:
public static String retrieveFullDateFromDateinAMPM ( Date date, String lang, String country ) {
SimpleDateFormat sdf =
new SimpleDateFormat("dd/MM/yy hh:mm a", Locale ( lang, country ) )
;
return sdf.format(date);
}
for more details see the java docs:
would it be not better to send to client always UTC ?
Client wold always have information about UTC and could convert it to local time ?
You need to set proper locale when parsing/formating a date object. If the locale is properly set in client browser, you should be able to access with javax.servlet.ServletRequest.getLocale() method.
Actually I done this from client side.Means after sending server time to client side(html, jsp....) then I write a bit of Jquery code like this.Here please convert the server date into .getTime() at your client side.(example new Date().getTime() == $('#message_creation_time').val())
<script type="text/javascript">
$(document).ready(function(){
var date = new Date(parseInt($('#message_creation_time').val()));
var localeSpecificTime = date.toLocaleTimeString().replace(/:\d+ /, ' ');
var dateString = date.toDateString();$('.message_creation_time_display').html(dateString+" "+localeSpecificTime);
});
</script>
Okay, so here's my issue in Android right now. On our Database there's a timestamp in this format 8/15/2013 2:00:48 PM and through a .NET WebService I get that same time like this in Android: 2013-08-15T14:00:48-07:00. Now I want to convert this format into a Date Time format that I can use for comparison (for example this webservice provides every instance where a device failed at logging in so we want to check the amount of time between occurances to see if there's any issues). Below I have this code where I'm trying to use JODA Time but it's still not returning the correct format:
public static Date convertStringToDate(String input) {
String pattern = "yyyy-MM-dd'T'HH:mm:ssZ";
DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern);
DateTime dateTime = formatter.parseDateTime(input);
return dateTime.toDate();
//printout shows: Thu Aug 15 17:00:48 EDT 2013
}
I know that the server is returning some crappy time format that is hard to work with (it took a while to get this to work in the iOS App we have, and even there it's still rather clunky) so I don't mind changing the webservice or the query if that would make things easier.
I have a very similar format, and I parse it using SimpleDateFormat, try this:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZ", Locale.US);
Date dateTime = format .parse(value);
What i understand is that you have your correct instance of date already and what you need is to parse it to String.
I suggest you use:
DateFormat formatter = new SimpleDateFormat("d/MM/yyyy hh:mm:ss a");
//this will give you the format '8/15/2013 2:00:48 PM'
String d = formatter.format(date);
Hope this helps.
EDIT:
Also seams you want to have your date instance in -07:00 timezone
So you can change your line
DateTime dateTime = formatter.parseDateTime(input);
for
DateTime dateTime = formatter.withZone(DateTimeZone.forID("-07:00")).parseDateTime(input);