Get Timestamp from web api

Hello Guys!

Currently I am integrating a website application to mobile apps. I got stuck at calling the Timestamp from the api.
The web Api is: ,“Timestamp”:"2016-10-13T00:55:57"
My html is look like this : Last Seen: {{assets.Timestamp}}
The output return as 0001-01-01T00:00:00.

Is there any part I had missing for calling this timestamp?

Hope someone can help me about this.

Thanks in advance!

What is your code to call the API and turn the response into something you can work with in your code (assets)?

Please edit your post, it is not very readable at the moment.
Use the </> button above the input field to format your code, command line output or error message (select the text first, then click the button or wrap it in ``` manually). Check the preview if it looks better. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.

Look at your post.
Look and read what I posted. Apply it. Look at your post again.

You still haven’t shown how assets is declared or initialized.

Declaration of assets in html :
*<ion-card ngFor = “let assets of assetList”>


Last Seen: {{assets.Timestamp}}
</ion-card-content//>

Sorry, but I don’t believe you. I can’t think of anything that would cause the code you have posted to generate the output you claim, so I think it more likely that you’re not actually posting your real code.

.html
<ion-header>

  <ion-navbar>
    <ion-title>Livetable</ion-title>
  </ion-navbar>

</ion-header>


<ion-content padding>
  <ion-card *ngFor = "let assets of assetList">
  <ion-card-header>
 <h1>{{assets.Name}} </h1>
  </ion-card-header>
 <ion-card-content>
    
    <ion-item>
      <ion-icon name="medical" item-start></ion-icon>
      <b>Company : </b>{{assets.Company}}
    </ion-item>

    <ion-item>
      <ion-icon name="pin" item-start></ion-icon>
 Last Seen: {{assets.Timestamp}}
    </ion-item>
     <ion-item>
     <b>Category: </b> {{assets.Category}} 
    </ion-item>
     <ion-item>
     <b>Category</b> {{assets.Engine}} 
    </ion-item>
</ion-card-content>
  </ion-card>
</ion-content>

.ts

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { RemoteServiceProvider } from './../../providers/remote-service/remote-service';

/**
 * Generated class for the LivetablePage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */


@Component({
  selector: 'page-livetable',
  templateUrl: 'livetable.html',
})
export class LivetablePage {

  assetList=[];

  constructor(public navCtrl: NavController, public navParams: NavParams, private remoteServiceProvider: RemoteServiceProvider) {

    this.getAsset();
    
  }

  
 getAsset(){
        this.remoteServiceProvider.getAsset().subscribe(data => this.assetList = data);

    }
      


}

provider .ts

import { Observable } from 'rxjs/Observable';
import { Injectable } from '@angular/core';
import {Http ,Response } from '@angular/http';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
  
@Injectable()
export class RemoteServiceProvider {


  constructor(private http: Http) {
    console.log('Hello RemoteServiceProvider Provider');
  }

private getApiUrl : string = "http:/--------api---";



getAsset(){

    return  this.http.get(this.getApiUrl+'------------api-------')
    .do(this.logResponse)
    .map(this.extractData)
    .catch(this.catchError)
}

private catchError(error: Response | any){
console.log(error)
return Observable.throw(error.json().error || "server Error");

}

private logResponse(res: Response){
  console.log(res);
}
private extractData(res: Response){
  return res.json();
}
}

So does assetList look like it should like? Add a console.log to check.

@hnlykci Are you sure you api is returning data the way you expect it, what is the difference between what you are expecting and what you get. Would you mind to post here both?

1 Like
return  this.http.get(this.getApiUrl+'xxx')
.do(this.logResponse)
.map(this.extractData)
.catch(this.catchError)

}

paste logResponse after calling your api please

Yes, you mentioned that before. That is your problem, not what we are asking for.
We are asking for the data you are working with. As clearly outputting that data doesn’t work as expected.

Hi Sujan12,

can you assist with adding timestamp inside chat bubbles?