cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert a BigDecimal to Date?

0 Kudos

Hi all,

I have a RFC provide me a time representation in BigDecimal format (yyyymmddhhmmss).

For example: '20051116082815' equals 16th Nov. 2005 8:28:15

What I have in mind is to bind the RFC time to a context node element of type "date" which I want to display in a textfield UI element.

So how can I convert the BigDecimal Format into the simpletype "date"?

I tried the following implementation. But it doesn`t seem to work.


IcaseResultElement caseResult.setCreateTime(
wdContext.nodeCaseOutput().currentCaseOutputElement()
.getEv_Create_Time().toString()
.substring(0,7));

"caseResult" is the node. "CreateTime" is the concerned node element of type "date". I used the substring method because I only need the date.

Thanks

Xiaopeng

Accepted Solutions (0)

Answers (4)

Answers (4)

0 Kudos

Hi all,

thank you very much for the valuable inputs. With your help I finally managed to get the correct display with the coding above.

SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
java.util.Date d = df.parse(wdContext.nodeCaseOutput().currentCaseOutputElement().getEv_Create_Time().toString());
java.sql.Date qd = new Date (d.getTime());
caseResult.setCreateTime(qd);

It took me some extra time as the input field only accepted java.sql.date.

Best regards,

Xiaopeng

Former Member
0 Kudos

Do you need to display only?

First try out the following code for conversion:

    
String s = "20051116082815";
BigDecimal b = new BigDecimal(s);
System.out.println(b);

SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
Date d = df.parse(s);
System.out.println(d);

SimpleDateFormat df2 = new SimpleDateFormat("MM/dd/yyyy");
System.out.print(df2.format(d));

To display the date in a read-only InputField (or TextView), create a <b>calculated </b>context attribute "FormattedDate", type string, <b>read-only</b>, bind property InputField.value (or TextView.text) to this attribute.

In the get-method for the calculated attribute, use the shown code to convert the BigDecimal value to the formatted date.

Armin

detlev_beutner
Active Contributor
0 Kudos

Hi Xiaopeng,

create a new SimpleDateFormat with the pattern "yyyyMMdd", use substring(0,8) (not: seven), and parse the resulting string with the SDF. With this, you have the date as java.util.date.

Hope it helps

Detlev

PS: Please consider rewarding points for helpful answers on SDN. Thanks in advance!

0 Kudos

I forgot the follwing:

What I`d like to have displayed in the textfield is something like '11/16/2005'.

Is that possible?