Reputation: 2236
Is there any way to use toLocaleString()
method in nativescript?
Please check toLocaleString - {N} Playground
<script>
export default {
data() {
return {
trDate: new Date(1579180347000).toLocaleString("tr"),
// should print 16.01.2020 16:12:27
};
}
};
</script>
Browser compatibility docs says :
Does it means that I better use some other package such as date-and-time to manage date data format ?
Upvotes: 1
Views: 936
Reputation: 300
As per @Manoj answer {N} !== NodeJS so to get it working you'll need to install Intl to your project knowing that toLocaleString
is using Intl
.
npm i intl
References:
Upvotes: 0
Reputation: 1732
I think, the problem is nodejs version because I have the same case on DigitalOcean auto-deploy feature.
I've solved it with engines property in package.json
{
"engines": {
"node":">=15"
}
}
more info about package.json - engines
Upvotes: 0
Reputation: 980
data() {
return {
trDate: new Date(1579180347000).toLocaleString("tr"),
}
}
maybe i'm silly, but you haven't mentioned your error this won't return a string but an object. can you please try
new Date(1579180347000).toLocaleString("tr-TR")
just to make sure it's not the problem.
also, in such scenarios what u should use is the computed not data.
computed: {
trDate: function () {
return new Date(1579180347000).toLocaleString("tr-TR");
}
}
Upvotes: 1
Reputation: 21908
{N} !== NodeJS
NativeScript just has a JavaScript runtime, only CommonJS modules work with it. Anything that depends on browser / node specific features, can't be used. You may try momentjs, it has a wide range of locale support.
Upvotes: 2