how can i replace time from date with time from string field in xpage using ssjs?

145 Views Asked by At

I want to replace time from field date(java.util.date) by the another value string and finally store the result in field with type date ,below my code

var dtDate = getComponent("RemindDatePS").getValue();   
var dtTime = getComponent("RemindTimePS").getValue();
  
   if (dtDate != null && dtTime != null) { 
       var dtDateTime:NotesDateTime = session.createDateTime(dtDate);
   dtDateTime.setLocalTime(dtTime ); 
1

There are 1 best solutions below

0
D.Bugger On

Using Java:

var df= new java.text.SimpleDateFormat("MM/dd/yy' 00:00T'HH:mm");
var dtDateTime= session.createDateTime(df.parse(dtDate + "T" + dtTime));

The code assumes that there will always be a space followed by 00:00 in the date string. AFAIK the date format should handle the concatenated string correctly (it ignores the 00:00). You might also use some function like @Left() to remove the time from dtDate and then concatenate that with the real time in dtTime.