admin管理员组文章数量:1025496
I am trying to do some date format in my application.
Suppose I am getting date stamp like "1573457092953.63"
And I am trying to do like below format.
"11/11/2019, 1:17:00"
So, I have used date.toLocaleString()
It is working fine in iOS, But, Getting issue in Android.
In iOS getting like 11/11/2019, 1:17:00 PM
Android getting like Mon Nov 11 1:17:00
How to fix this, Even I did not get anything from other forums.
Any suggestions?
I am trying to do some date format in my application.
Suppose I am getting date stamp like "1573457092953.63"
And I am trying to do like below format.
"11/11/2019, 1:17:00"
So, I have used date.toLocaleString()
It is working fine in iOS, But, Getting issue in Android.
In iOS getting like 11/11/2019, 1:17:00 PM
Android getting like Mon Nov 11 1:17:00
How to fix this, Even I did not get anything from other forums.
Any suggestions?
Share Improve this question edited Nov 12, 2019 at 8:23 Anilkumar iOS Developer asked Nov 11, 2019 at 7:59 Anilkumar iOS DeveloperAnilkumar iOS Developer 3,76510 gold badges61 silver badges120 bronze badges 1- 1 Try to look at momentJS – DevAS Commented Nov 11, 2019 at 11:44
2 Answers
Reset to default 3Unfortunately, toLocaleString()
doesn't work on Android. Please, check the following link.
The workaround is to create a custom mapping and to use it:
const dateTimeMapping = {
en: {
onlyTime: 'h:mm A',
shortDate: 'ddd, D MMMM',
longDate: 'D MMMM YYYY h:mm A',
},
de: {
onlyTime: 'H:mm',
shortDate: 'ddd, D. MMMM',
longDate: 'LLL',
},
it: {
onlyTime: 'H:mm',
shortDate: 'ddd D MMMM',
longDate: 'D MMMM YYYY HH:MM',
},
}
Pass the locale property and the type of the format:
const result = dateTimeMapping[locale][type];
About the number formatting, you can read more here.
I found finally some library called
moment
"moment": "^2.24.0" // in package.json file
import Moment from 'moment';
Moment(date).format('DD/MM/YYYY, hh:mm:ss')
Output is 11/11/2019, 1:17:00
Hope this will help someone in future.
It is working fine for both iOS and Andorid domains.
I am trying to do some date format in my application.
Suppose I am getting date stamp like "1573457092953.63"
And I am trying to do like below format.
"11/11/2019, 1:17:00"
So, I have used date.toLocaleString()
It is working fine in iOS, But, Getting issue in Android.
In iOS getting like 11/11/2019, 1:17:00 PM
Android getting like Mon Nov 11 1:17:00
How to fix this, Even I did not get anything from other forums.
Any suggestions?
I am trying to do some date format in my application.
Suppose I am getting date stamp like "1573457092953.63"
And I am trying to do like below format.
"11/11/2019, 1:17:00"
So, I have used date.toLocaleString()
It is working fine in iOS, But, Getting issue in Android.
In iOS getting like 11/11/2019, 1:17:00 PM
Android getting like Mon Nov 11 1:17:00
How to fix this, Even I did not get anything from other forums.
Any suggestions?
Share Improve this question edited Nov 12, 2019 at 8:23 Anilkumar iOS Developer asked Nov 11, 2019 at 7:59 Anilkumar iOS DeveloperAnilkumar iOS Developer 3,76510 gold badges61 silver badges120 bronze badges 1- 1 Try to look at momentJS – DevAS Commented Nov 11, 2019 at 11:44
2 Answers
Reset to default 3Unfortunately, toLocaleString()
doesn't work on Android. Please, check the following link.
The workaround is to create a custom mapping and to use it:
const dateTimeMapping = {
en: {
onlyTime: 'h:mm A',
shortDate: 'ddd, D MMMM',
longDate: 'D MMMM YYYY h:mm A',
},
de: {
onlyTime: 'H:mm',
shortDate: 'ddd, D. MMMM',
longDate: 'LLL',
},
it: {
onlyTime: 'H:mm',
shortDate: 'ddd D MMMM',
longDate: 'D MMMM YYYY HH:MM',
},
}
Pass the locale property and the type of the format:
const result = dateTimeMapping[locale][type];
About the number formatting, you can read more here.
I found finally some library called
moment
"moment": "^2.24.0" // in package.json file
import Moment from 'moment';
Moment(date).format('DD/MM/YYYY, hh:mm:ss')
Output is 11/11/2019, 1:17:00
Hope this will help someone in future.
It is working fine for both iOS and Andorid domains.
本文标签: javascripttoLocaleString() is not working in Android for React NativeStack Overflow
版权声明:本文标题:javascript - toLocaleString() is not working in Android for React Native - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745636943a2160509.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论