Search code examples
angularjsdatetimesubstr

How to get date and time separtely


I'm just a beginner of angularJs. I need to get only half value from input.

This is my code. I'm using datetime-picker

<input class="form-control" placeholder="Choose date and time" name="datetime" value="datetime" ng-model="date3.data" datetime-picker date-format="yyyy-MM-dd HH:mm:ss" close-on-select="false" />

Now I get 2016-06-29 12:14:00

I need to separate date and time -like date = 2016-06-20 and time = 12:14:00


Solution

  • Just use split method in your string

    t = "2016-06-29 12:14:00"
    var a = t.split(" ");
    var date = a[0];
    var time = a[1];