date format in email message - Foglight for Databases - Foglight for Databases - Dell Community

date format in email message

date format in email message

This question is answered

Hi Everyone,

I am trying to include alarm date creation time in my email alert and using the following to get the same:

scope.get("alarms")[0].createdTime

It is generating time in "YYYY-MM-DD HH24:MI:SS.MS" format.

I need it in "MM/DD/YYYY HH24:MI:SS"

Can someone help with this?

Best Regards,

Murali

Verified Answer
  • Hi,

     The timestamp you’re getting back from the query/line is a TimeStamp object, so you can format it.

    Here is some example code for controlling the format:

    //=====================

    import java.sql.Timestamp;

    import java.text.SimpleDateFormat;

    SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy HH:mm:ss");

     

    tstamp =  scope.get("alarms")[0].createdTime;

    return dateFormat.format( tstamp );

    //=====================

    You can change the format by changing the string you give SimpleDateFormat.  I would suggest you google “Java SimpleDateFormat” (without the quotes) to get more information on the available values for the format string.

     David

    David Judge (Disclosure: I work for D Software the local office partner for Dell Software in EMEA's emerging markets)

All Replies
  • Hi,

     The timestamp you’re getting back from the query/line is a TimeStamp object, so you can format it.

    Here is some example code for controlling the format:

    //=====================

    import java.sql.Timestamp;

    import java.text.SimpleDateFormat;

    SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy HH:mm:ss");

     

    tstamp =  scope.get("alarms")[0].createdTime;

    return dateFormat.format( tstamp );

    //=====================

    You can change the format by changing the string you give SimpleDateFormat.  I would suggest you google “Java SimpleDateFormat” (without the quotes) to get more information on the available values for the format string.

     David

    David Judge (Disclosure: I work for D Software the local office partner for Dell Software in EMEA's emerging markets)

  • Thank you so much. It worked.