How to format the date property obtained from diagram or model element

Date is a very important property in model since it recorded the timestamp when a diagram or model element was being created or modified. In Visual Paradigm all diagrams and most of the model elements are having date property for storing its creation date time, as well as the last modified date time. In this article we will show you how to retrieve the date time property and format it into human readable text.

For diagrams (inherit from IDiagramUIModel) and model elements (inherit form IHasChildrenBaseModelElement), the creation date and last modified date can be retrieved from the getPmCreateDateTime() and getPmLastModified() methods.

String createDate = element.getPmCreateDateTime();

This method return the date and time into a String type variable with actual value as the system time milliseconds. After retrieve the value we first can convert it into a java.util.Date object.

Date d = new Date();
d.setTime(new Long(createDate).longValue());

Once it is converted into Data object, we can make use of java.text.SimpleDateFormat to format it into a human readable format.

// display the date as dd/MM/YYYY
SimpleDateFormat sd = new SimpleDateFormat("dd/MM/YYYY");
// and print it to message pane
ApplicationManager.instance().getViewManager().showMessage(sd.format(d));

Related Articles

Related Links

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply