Hi i have to append Date to a URL, maintaining its Datatype as Date and not as String
When in append Date to URL as "?date=" + $(target).val();
i fetch it through #RequestParameter in my Controller
But the problem here lies that i cant access it as Date but as String.
If i access it as Date it does not gives an error but changes the format of the Date from 2017-05-12 00:00:00 to something like Fri MAY 12 00:00:00 IST 2017.
So i need to send data as date through AJAX so when i access in my Controller i can maintain its format
As far as i know when i fetch the data as Date it gives me internal representation of Date because there is internal conversion of String to Date
Thus i need to know how i can send date through URL in AJAX
You can't pass types via GET URL parameters.
You need to convert the type on your java code.
For example:
new SimpleDateFormat( "MM/dd/yyyy H:m:s" ).parse( #RequestParam( "date" ) )
It's all in the javadoc for SimpleDateFormat
Related
I am converting string to date using a tConvertType component in Talend.The data(source is in String) is getting loaded when I do the date pattern yyyy-mm-dd but when I try with timestamp yyyy-MM-dd HH:mm:ss then I am getting an error. The data from the source has the timestamp but then I am getting an error.
For Eg : I have the source as 2015-09-03 14:14:90 , since data is in string so used tconverttype and then for destination the data type is date. But if I use timestamp then I am getting an error of Unparseable date and if I change to yyyy-mm-dd then the data is coming as 2015-09-03 00:00:00 which is wrong
try
convert(timestamp,expression)
i had the same problem in the past and convert fixed that
Using the type date and date format "yyyy-MM-dd' 'HH:mm:ss" it works fine
I recommand you to use date format by pressing Ctrl+space and choose from the list.
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
I have a one rest method from Spring3 which returns expected JSON response except date which is in timestamp.
In database date is stored as 2013-08-08 00:30:00. Before sending response to the application, the date I am getting as 2013-08-08 00:30:00. I have checked it in debug mode. But after complete execution of rest-service, I got the date in long format as 1375902000000.
I want to return same timestamp format instead of long format.
I don't want to convert long timestamp to again date format at client side.
By default it is serialized as long if you want to send it like 2013-08-08 00:30:00 you may try asString()
You could do the following to keep your desire date format:
Declare the bean property as String.
Format the date object according to your desire format, example yyyy-dd-MM hh:mm:ss
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.
in my App User Selects Date like 2013-01-02
but in MySql DB the column format is like 02-Jan-2013 so want change the Date Format
my code is:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
SimpleDateFormat formatter1 = new SimpleDateFormat("dd-mmm-yyyy");
Date start_date = (Date)formatter.parse(GBRF.getStart_date());//GBRF.getStart_date() returns Form Data as 2013-01-02
String dt=formatter1.format(start_date);
Date sd=(Date)formatter1.parse(dt);
at the End sd print Date like this Wed Jan 02 00:01:00 IST 2013
i dont want that format..
just i want like 02-Jan-2013
give me an idea..
Thanks in Advance
You can format Date into String with SimpleDateFormat, after that if you try to print date instance it will invoke toString() method of Date class which has no change in output and you can't alter that output because it is coming from toString() implmentation
Note: in your format you need to use M for month (note capital M)
A Date object does not have a format in itself. It holds just a point in time. The format comes into play when you convert it to or from a String.
Also note that m in the format is used for minutes not months. So you probably want a format like dd-MMM-yyyy.
Try
System.out.println(formatter1.format(sd));
to get the date printed as you like it.
You need to change your date format first :
`SimpleDateFormat formatter1 = new SimpleDateFormat("dd-MMM-yyyy");`
In your case, if you just print dt, it should print date in the required format instead of converting it into Date object again i.e. sd
When you are printing sd, without any formatting it will print the default String implementation of Date object which is exactly what you are seeing as an output