I'm getting info from an API, and what I want to do is get the response of date time. This is part of my code:
function perDetail(){
$http.get('/api/values')
.then(function(data){
$scope.details = data.data.Response;
});
}
Part of what i get is:
"Date":"2018-07-16T18:00:00"
And what I wanna do is get the hour:
18:00
Someone can guide me, please? I know there's a split and splice method, but I can't get the value. Maybe sounds too easy but right now, I'm stuck with this.
I'm using AngularJs and Javascript.
Thanx in advance.
Here's one way to do it.
var date = "2018-07-16T18:00:00";
var time = date.split("T")[1]; // time is "18:00:00"
var justHour = time.slice(0, 5); //from index 0 to index 5 (first 5 characters)
return justHour; //"18:00"
If I understood correctly, "Date" is a key in the response object you are getting from your API call, right? And you just want to get the hours:minutes part in the corresponding value?
If that's correct, I think slicing the value in the right places would do the job:
data["Date"].slice(-8, -3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With