简体   繁体   中英

sencha touch dateFormat not working?

i'm very new to sencha touch and i have a problem with the dateFormat.

So, here is some code, i wrote:

First of all I have a datepickerfield to choose a date.

        var activityDateCreator = {
        xtype: 'datepickerfield',
        destroyPickerOnHide: true,
        name: 'date',
        label: 'Datum',
        dateFormat: 'd.m.Y',
        value: new Date(),
        picker: {
            yearFrom: 2013,
            yearTo: 2014
        },
        required: true
    };

At this point the dateFormat is displayed, how i want it to be.

The date is saved in the localStorage.

the model does look like that:

Ext.define('RMA-App.model.Activity', {
extend: 'Ext.data.Model',

config: {
    idProperty: 'id',
    fields: [
        { name: 'id', type: 'int' },
        { name: 'name', type: 'string' },
        { name: 'sport', type: 'string' },
        { name: 'date', type: 'date' , dateFormat: 'd.m.Y'},
        { name: 'time', type: 'string' },
        { name: 'street', type: 'string' },
        { name: 'place', type: 'string' },
        { name: 'comments', type: 'string' },
        { name: 'save', type: 'boolean'},
        { name: 'latitude', type: 'number'},
        { name: 'longitude', type: 'number' }
    ],
    validations:[
        { type: 'presence', field: 'id' },
        { type: 'presence', name: 'date'},
        { type: 'presence', name: 'name', message: "Bitte geben Sie Ihren Namen an!"},
        { type: 'presence', name: 'time', message: "Bitte geben Sie eine Zeit an!"},
        { type: 'format', name: 'time', matcher: /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/, 
        message: "Bitte stellen Sie sicher, dass sie die Zeit im richtigen Format angeben. <br>Beispiel: 08:30"},
        { type: 'presence', name: 'street', message: "Bitte geben Sie die Straße für den Treffpunkt an!"}

    ]
}

});

Now i want to show the date in a textfield, which is not in the same view as the datepicker.

  var activityDate = { xtype: 'textfield', name: 'date', label: 'Datum', readOnly: true }; 

in the browser i can see the date, but it's shown like this: 'Fri Aug 23 2013 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)' instead of this: '23.08.2013'

Hope someone has a solution for my problem.

ps.: i'm sorry for my poor english :p

You can convert Fri Aug 23 2013 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit) format into 23.08.2013 .

In Extjs

var date = new Date('Fri Aug 23 2013 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)');
console.log(Ext.Date.format(date, 'd.m.Y'));

In pure Javascript

var date = new Date('Fri Aug 23 2013 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)');
var curr_date = date.getDate();
var curr_month = date.getMonth() + 1; 
var curr_year = date.getFullYear();
console.log(curr_date + "." + curr_month + "." + curr_year);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM