Expression Binding - Format Date

You can format a date in an expression binding by using the dateFormat and now functions.

To make a label that updates to show the current time

Let's create a label that updates every second to reflect the current time.

  1. Drag a Label component onto the window.

  2. Select the label's Text property binding icon and select Expression binding.

  3. Enter the following code into the expression, and click OK.

    dateFormat(now(1000), "MMM d, yyyy hh:mm:s a"

    The dateFormat function takes two arguments. The first argument is any date type variable. The second argument refers to the date format that you want returned. The now function returns the current time and in this case it will update every second.
    For more information see the Appendix.