Hi All,
I am trying to fetch date property from crx as below :
Calendar cal = Node.getProperty("date").getValue().getDate();
"date" is of type "String" and has a value currently of "2014-02-01".
As per one of the article, http://aem.matelli.org/fetching-properties-from-dialogs/ this is one of the way to get the date value
1] Can you please guide me as to where I am missing things and what needs to be corrected.
Any thoughts/pointers on this will be helpful.
Solved! Go to Solution.
Views
Replies
Total Likes
If the property is stored as string in JCR then why are you reading it as date in the JCR API-
Calendar cal = Calendar.getInstance(); String date = node.getProperty("date").getString() SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MMM-dd"); Date dateObj = formatter.parse(date); cal.setTime(dateObj);
Views
Replies
Total Likes
Does this code return Date object or calender object?
Node.getProperty("date").getValue().getDate();
askdctm wrote...
Hi All,
I am trying to fetch date property from
crx as below:
Calendar
cal = Node. getProperty ( "date"). getValue ( ). getDate ( );
"
date " is of type "String" and has a value currently of "2014-02-01".
As per one of the article, http://aem.matelli.org/fetching-properties-from-dialogs/ this is one of the
way to get the date value
1] Can you please guide me as to where I am missing things and what needs to be corrected.
Any thoughts/pointers on this will be helpful.
Views
Replies
Total Likes
Hi Jitendra,
Thank you for your reply.
As of now, it is not returning anything. It is throwing ValueFormatException.
As oer the documentation, looks like it should return Calendar object.
Views
Replies
Total Likes
Hi All,
Any thoughts/pointers on this will be helpful.
Views
Replies
Total Likes
This would work only if you are using xtype as datetime. That would store it as a Date and then you can retrieve it like you are trying.
Views
Replies
Total Likes
Hi Abhinav,
Thank you for your reply.
https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/org/apache/jackrabbit/commons/JcrUtils.html lists JcrUtils.getDateProperty.
Can you please let me know if it will work in the scenario mentioned.
Views
Replies
Total Likes
Hi All,
Any thoughts/pointers on the above will be helpful.
Views
Replies
Total Likes
ValueFormatException, this exception occurs because "2014-02-01" isn't Date which JCR supports. Does it?. I guess, "date" property isn't Date type. So, you can't except value in date.
I would recommend you to read "date" property as String and convert it Date object. This is the simplest thing.
Jitendra
Views
Replies
Total Likes
If the property is stored as string in JCR then why are you reading it as date in the JCR API-
Calendar cal = Calendar.getInstance(); String date = node.getProperty("date").getString() SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MMM-dd"); Date dateObj = formatter.parse(date); cal.setTime(dateObj);
Views
Replies
Total Likes
Hi
Please go through this Stackoverflow article.
Link:- http://stackoverflow.com/questions/22150895/save-date-as-timestamp-in-cq5
// JSP code
<%@page import="java.text.SimpleDateFormat,java.util.Date"%> <% SimpleDateFormat displayDateFormat = new SimpleDateFormat("dd MMM yyyy"); String dateField = properties.get("nameofdatefield", ""); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy"); Date formattedDate = sdf.parse(dateField); String formattedDateStr = displayDateFormat.format(formattedDate); out.println('Example of formated string'+formattedDateStr); %>
Reference Forum Thread :- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...
I hope this would help you.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes
Hi Jitendra/Kunal/Kautuk/Abhinav,
Thank you for your help here. Followed the thing mentioned above and it worked.
Views
Replies
Total Likes
Views
Likes
Replies