Skip to Content
0

Insert Current year in in UI5

May 24, 2017 at 01:32 PM

98

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Jun Wu May 24, 2017 at 01:45 PM
0

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

populate currentYear in your controller and set it to model

Share
10 |10000 characters needed characters left characters exceeded
Akhilesh Upadhyay May 24, 2017 at 02:20 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
Shilpa Ramamurthy
May 25, 2017 at 05:43 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded