cancel
Showing results for 
Search instead for 
Did you mean: 

Simple question, how to add "millisecond" to a field in mapping

Former Member
0 Kudos

Hi,

We need to add a timstamp to a field at runtime. The mapping function we used is: currentDate .... but the mask for time does not contains millisecond ...

dd/MM/yyyy HH:mm:ss

How can we get millisecond?

merci ! A+

mo

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

By using UDF we can achieve this,

write UDF like this, here no need to give the input parameter if you want the system current date.

1.import java.util.Date;

2.long msec = System.currentTimeMillis();

3.return msec.

If you want to give some date rather than system date then

1.import java.util.Date;

2.input parameter dat;

3.long msec = dat.currentTimeMillis();

4.return msec.

vijay_b4
Active Contributor
0 Kudos

Hi,

Please try this:

IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();

Object attributeValue = wdContext.currentDateFieldsElement().getAttributeValue(fieldName);

Date theDate =

(Date) wdContext.currentDateFieldsElement().getAttributeValue(

fieldName);

IWDAttributeInfo attributeInfo =

wdContext.nodeDateFields().getNodeInfo().getAttribute(fieldName);

Calendar c = Calendar.getInstance();

c.set(Calendar.HOUR_OF_DAY, 0);

c.set(Calendar.MINUTE, 0);

c.set(Calendar.SECOND, 0);

c.set(Calendar.MILLISECOND, 0);

Date currentDate = new Date(c.getTimeInMillis());

if (theDate.before(currentDate)) {

{

// Throw an error message

msgMgr.reportContextAttributeMessage(

wdContext.currentDateFieldsElement(),

attributeInfo,

IMessageRequisitionForm.MISSING_INPUT,

new Object[] { fieldLabel },

true);

}

}

}

Reward points if this helps

Regards

Vani.

Former Member
0 Kudos

Hi,

don't know if it's possible with standard functions, but

you could write a UDF and using:

(import java.util.Date;)

long t0 = System.currentTimeMillis();

and then you can concat the value.

If you need just the format you can also concat a constant "0000".

Regards

Patrick

Former Member
0 Kudos

many thank for your rapid answers !

A+

Former Member
0 Kudos

If you want to have milliseconds in a date format, try to use the "S" pattern (yyyy-mm-dd hh:mi:ss.SSS) in the datetrans function (it should work cuz it is built upon the SimpleDateFormat class) or write your own UDF importing the java.text.SimpleDateFormat package.

I use it to format debug log time stamps and it works pretty fine

Rgds

Chris

Former Member
0 Kudos

I have tried the following format: (yyyy-mm-dd hh:mi:ss.SSS) and i am getting at least a number Which seem to be the milliseconds ...

Thank !

Former Member
0 Kudos

hi

write a UDF and do it

use Date/Calender java classes

use this code

Calendar now = Calendar.getInstance();

String millisec=String.valueOf(now.getTimeInMillis());

return millisec;

rgds

Arun