on 2015 Aug 11 11:51 AM
Hi All,
I created a table with XML view.
This is how i have binded.
<items>
<ColumnListItem>
<cells>
<Text
text="{empModel>Empno}" />
<Text
text="{empModel>Fname}" />
<Text
text="{empModel>Lname}" />
<Text
text="{empModel>Addrs}" />
<Text
text="{empModel>Desgn}" />
<Text
text="{empModel>Dob}" />
</cells>
</ColumnListItem>
</items>
But my date format which is coming from gateway is in this format "2015-05-05T05:13:19.3167890".
I want to display it as 05-05-2015.
I also have a datepicker and in that datepicker date format is not selected in this format. So basically how i can perform the POST operations?
I am a beginner so if possible attach a simple code for reference.
Thanks in advance.
Request clarification before answering.
Hi,
you can try 2 options
1. use type and formatOptions
SAPUI5 Explored
2. use formattrer function
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Raghu,
please, try that
Code in view
<Text text="{path: 'empModel>Dob',
formatter: '.formatDate'}"
/>
function in controller:
formatDate : function(v) {
jQuery.sap.require("sap.ui.core.format.DateFormat");
var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern: "dd-MM-YYYY"});
return oDateFormat.format(new Date(v));
}
Regards,
Raman
Well, you forgot to specify the input pattern Also, you used brackets surrounding the model field you are binding, but this is incorrect too (you are already binding)
Change it to
<Text text="{
path: 'empModel>Dob',
type: 'sap.ui.model.type.Date',
formatOptions: {
source: {
pattern: 'yyyy-MM-ddTHH:mm:ss.AAAAAAA'
},
pattern: 'yyyy/MM/dd'
}
}" />
You probably did something wrong then... works for me in this working example: Edit fiddle - JSFiddle
Since your example date was "2015-05-05T05:13:19.3167890", I assumed the last 7 digits were milliseconds.
But obviously, milliseconds can only be maximum of 3 digits (hence the milli) so i'm not sure what those last 7 digits are. If you look at the example I just provided, you'll see a correct date
You are welcome:)
UI5 uses this syntax for binding. Dot means a local function/type.
Read more SAPUI5 SDK - Demo Kit
Hi Robin,
From OData service I am receiving the date in following format:
/Date(1354665600000)/"
and I am binding it to sap.ui.commons.DatePicker.
So what should be the source pattern in my case?? I dont want to use formatter function as it is not updating the changed values in model (I am using json model).
Thanks and Regards,
Sagar
I have used the following code in the controller where I make my table in:
var datetimecol = new sap.ui.table.Column({label: "{i18n>Date_Time}", editable: false,
template: new sap.ui.commons.TextField( {
value: {
path: "DATETIME",
formatter: sap.ui.demo.table.util.Formatter.date,
},editable : false,
}),
sortProperty: "Date_Time", width: "12em" });
oTable.addColumn(datetimecol);
This creates a column and adds it to the table.
This is the code I use for my formatting of the date-time:
date : function(fValue){
if(fValue != null){
fValue = new Date(parseInt(fValue.substr(6)));
var sLocale = sap.ui.getCore().getConfiguration().getLanguage();
var oBundle = jQuery.sap.resources({url : "i18n/messageBundle.properties", locale: sLocale});
var dateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern : oBundle.getText("DateTimeFormat") });
fValue = dateFormat.format(fValue);
return fValue;
}
return fValue;
},
I also check the locale so it automatically adjusts to the right time.
The i18n/messageBundle.properties content is:
#DateTime format
DateTimeFormat=dd/MM/yyyy HH:mm:ss
I've done this so that it's possible to change the date time for America or Europe or anywhere else.
I hope this code can be of use to you.
Kind regards,
Max
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Solution provided by Raman is working but i am wondering that whu solution of
is not working in my case. Where might be error?
And one more question.
Suppose i am selecting date from calendar then how i will convert this date for Gateway post?
If i will follow the Raman code then in pattern i will define like this?? pattern: "yyyy-MM-ddTHH:mm:ss.AAAAAAA"??
Same code will be applicable for javascript view also?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Both solution provided by and should work.
Here you may check the document.
sap.ui.core.format.DateFormat - User Interface Add-On for SAP NetWeaver - SAP Library
JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.core.format.DateFormat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Raghu,
You can write the below code in your formatter function
Thanks,
Naga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 9 | |
| 7 | |
| 6 | |
| 4 | |
| 4 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.