Skip to Content
avatar image
Former Member

Insert Current year in in UI5

Hi

I want to add current year in <LABEL text=" this is current year 2017">

How can I add current year value in text of a LABEL in UI5.

Thanks

Puneet

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • May 24, 2017 at 01:45 PM

    <LABEL text=" this is current year {/currentYear}">

    populate currentYear in your controller and set it to model

    Add comment
    10|10000 characters needed characters exceeded

  • May 24, 2017 at 02:20 PM

    if you are not getting current year from service and its not in any model, you can get using javascript as;

    var d = new Date();
    var currentYear = d.getFullYear(); // return 2017

    now you can set currentYear to your label using setText(currentYear) or define one model with this year data and bind this model.

    Add comment
    10|10000 characters needed characters exceeded

  • May 25, 2017 at 05:43 AM

    Hi Puneet,

    This can easily be done with a formatter and i18n parameters.

    • In your view:

    <Label text="{path:'i18n>YEAR_STRING', formatter:'.formatCurrentYear'}"/>

    • In your controller:

    formatCurrentYear: function(key){

    var d = new Date();
    var currentYear = d.getFullYear();

    //get the reference to the i18n resource bundle here

    return oResourceBundle.getText(key, [currentYear]);

    }

    • In your i18n properties file

    YEAR_STRING = this is current year {0}

    Hope this helps!

    Thanks and best regards,

    Shilpa

    Add comment
    10|10000 characters needed characters exceeded