Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Trim string, e.g. for date picker

Hello together!

I have a problem to trim my string i get from the date picker.

I recive this string:

Fri May 28 2010 16:46:41 GMT+0200 (CEST)

(Ok… strange, few minutes ago i got the date as 2010-05-28 ?!)

So, anyone know how to get the old date back?

But back to my old question:

I want to trim the (old) string:

2010-05-28 16:46:41 GMT+0200



i tried it with:

datePicker.addEventListener('change', function(e){
    searchDate = e.value;  // here i get an output with Ti.API.Info
    searchDate = searchDate.substring(0,9); // here i get nothing when i try t get an output with Ti.API.info

i tried substr, substring non of these are working.

Any suggestions?

— asked May 28th 2010 by Michael Gajda
  • crop
  • date
  • datepicker
  • iphone
  • picker
  • string
  • substr
  • substring
  • trim

1 Answer

  • Accepted Answer

    Try something like this…

        var pickerdate = e.value;
        var day = pickerdate.getDate();
        var month = pickerdate.getMonth();
        var year = pickerdate.getFullYear();
        var newdate = year + "-" + month + "-" + day;
    — answered May 28th 2010 by Andrew Burgess
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.