on 2016 Aug 26 9:10 AM
Hey Experts!
I have a problem with my date formatter on my View. My date should be formatted according to the user profile. I get my date time from a database by a oDataModel like: Fri Aug 26 2016 02:00:00 GMT+0200 (W. Europe Daylight Time)
and as i mentioned i want to fomat it accoring to the user profile with this code snipped:
// For date/time values require the DateFormat class
jQuery.sap.require(
'sap.ui.core.format.DateFormat'
)
// Instantiate the date, time, datetime classes, without a parameter or based on a certain style (either 'short', 'medium' or 'long')
var
oDateFormat = sap.ui.core.format.DateFormat.getDateInstance();
// Use any of the variables above to format a date or time value (using JavaScript "Date" objects):
oDateFormat .format(
new
Date());
The problem is my oData date is a string and not a js-object which i need to format my oData model output correctly.
Have you an idea to fix this problem? fyi i want to implement this datefommater into a ColumListItem control which used as a template to bind my models to a table below this text you will see how i do it at the moment:
Here is how my template looks like with a working but static date time formatter 1# (i want replace this static fomatter with the new method above):
1# My static formatter
2# My template for binding
Best Regards,
Danilo
Request clarification before answering.
Hi Danilo,
I think the date format you are getting from odata might be in this format
var date = "2016-08-26T00:00:00";
Now you want to convert this date in the regular format like "MM-dd-yyyy"
to achieve this please follow the piece of code :
var frmt2 = sap.ui.core.format.DateFormat.getDateInstance({pattern:"MM-dd-yyyy"})
var new_date = frmt2.format(date)
now you use this new_date to display.
Thanks,
Deepak.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Deepak,
you are correct with your variant of code it works also with this string:
var sDate= new sap.m.Text({ text: "Fri Aug 26 2016 02:00:00 GMT+0200 (W. Europe Daylight Time)" })
and this is the string which i got from my model.
But now i know its working when i paste a string in my frmt2.format(new Data(sDate)) but i need the dates from my model like i get it before with a path to my oDataModel( without the property: "type" in this case:
var sDate= new sap.m.Text({ text: { path: "project>ENDDATE"}})
But then my output will be a empty string
yes I am expecting that because our shell takes this control and changes that depends the user profile I also have to implement this control and show the model dates which I fetched like i did it before. The thing what is confusing me is that I can not fetch the model anymore if I do it like the post above.
I am not sure weather it is a correct approach or not you can do like this
for example now you are getting date like this
model.results[0].date = "2016-08-26T00:00:00"
now you want to chane this format of the date
var frmt2 = sap.ui.core.format.DateFormat.getDateInstance({pattern:"MM-dd-yyyy"})
model.results[0].date = frmt2.format(model.results[0].date)
Now the date format in your model will be changed in the required pattern and you can bind it to the view.
Thanks,
Deepak.
Unfortunately not! That is the point why i am so confused. I should get the date like all my other properties which i fetch from the model but if i want to commit my variable with the text string it will be empty. If I write immediately write this textControl in my oTableTemplate the following code it works fine with the right date:
var sDate= new sap.m.Text({ text: { path: "project>ENDDATE"}})
That means in my point of view that i can fetch a model on my view in a variable like I did it with the sDate
Or I am wrong? Thats why i tried to put the sDate into my frmt2.format(new Data(sDate)) in hope that sDate commit the right string to this function.
User | Count |
---|---|
81 | |
30 | |
10 | |
8 | |
8 | |
7 | |
6 | |
6 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.