I’m trying to get the timezone with getDatePattern,
I have a provider, this is the code that I have in it:
import { HttpClient } from ‘@angular/common/http’;
import { Injectable } from ‘@angular/core’;
import { Globalization } from ‘@ionic-native/globalization’;
@Injectable()
export class TimezoneProvider {
public segundos :any;
constructor(public globalization: Globalization) {}
getTimeZone(){
this.globalization.getDatePattern (
{ formatLength: 'short', selector: 'date and time'} )
.then(res => {
let seconds = res.utc_offset;
this.segundos = seconds;
});
return this.segundos
}
}
in the page where I using the provider,
the variable is shown undefined
segundosTimeZone;
constructor(public navCtrl: NavController, public alertCtrl: AlertController, public timeZone:TimezoneProvider) {
this.segundosTimeZone = this.timeZone.getTimeZone();
console.log(this.segundosTimeZone);
}
Thanks!