0

I am receiving json data in my javascript as a list of strings that contain date and time of certain events.

I construct an array and store these in the array.

However the storage is in the format of dd/mm/yyyy hh:mm:ss. I was wondering if there is a way to just extract the date part of this string from the array.

// run a loop to parse thru all elements in the array. //
t = (Service_date_from[count]); // 't' is what contains the date time once extracted from the array with a counter variable called `count`

Is there any kind of date formating functionality in javascript?

Philo
  • 1,931
  • 12
  • 39
  • 77
  • You can split the string on the space: http://stackoverflow.com/questions/96428/how-do-i-split-this-string-with-javascript – isherwood Feb 27 '13 at 19:23
  • Googling `javascript date` provides a wealth of information on this topic. The first link quickly describes the functions mentioned below. Did you even try to search? – jahroy Feb 27 '13 at 19:36
  • @jahroy yes i did, I have been posting on stackoverflow for a bit, I think I understand the inherent concepts of researching an idea. But I also like discussing an idea at the same time I research. This broadens my search criteria. thanks for your reply. – Philo Feb 27 '13 at 19:40
  • @isherwood thanks dude. I lived in St cloud, MN for abt 5 yrs. good times. – Philo Feb 27 '13 at 19:43

1 Answers1

3

If it's always formatted that way, you can simply use substr

var idx = t.indexOf(" ");
var timeStr = t.substr(idx + 1);
Jeremy T
  • 1,273
  • 1
  • 10
  • 14
  • yeah dude, I was wondering if there was any kind of date time functionality in javascript to trim variables of date time type ? – Philo Feb 27 '13 at 19:26
  • 2
    So you'd convert from a string to a Date object back to a string again? There's `t.toTimeString()`, or you could just do something like `t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds()` if you want more specific control – Jeremy T Feb 27 '13 at 19:28