How to import date and set node. | Community
Skip to main content
Level 3
November 22, 2021
Solved

How to import date and set node.

  • November 22, 2021
  • 1 reply
  • 654 views

Hi,

 

I am importing data from a json and I am finding problem while setting date field.

I am using java util calendar and using set function.

here is the peace of code

'Calendar opCal = Calendar.getInstance() ;

if (OpDate.length() > 0) {
int ddOp = Integer.parseInt(schOpDate.substring(0,2));
int mmOp = Integer.parseInt(schOpDate.substring(3,5));
int yyyyOp = Integer.parseInt(schOpDate.substring(6));
opCal.clear();
opCal.set(yyyyOp,mmOp,ddOp);
}'
'chContent.setProperty("customDate", opCal);'


 but in some cases it setting wrong date like for 12-10-2021, its setting 13-11-2021. I dont know why its doing that.

Is there a better way of doing it ?

 

Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Siva_Sogalapalli

@hptarora 

 

did you try like this? 

 

DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'+00:00'");

 

you can change DateFormat pattern as per your requirement. https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html 

        

 java.util.Date date = inputFormat.parse(inputDate);

      

Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

calendar.setTime(date);

 

chContent.setProperty("customDate",calendar);

 

 

 

1 reply

Siva_Sogalapalli
Community Advisor
Siva_SogalapalliCommunity AdvisorAccepted solution
Community Advisor
November 22, 2021

@hptarora 

 

did you try like this? 

 

DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'+00:00'");

 

you can change DateFormat pattern as per your requirement. https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html 

        

 java.util.Date date = inputFormat.parse(inputDate);

      

Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

calendar.setTime(date);

 

chContent.setProperty("customDate",calendar);