Share the React Native time conversion format tool class, reactnative
This article provides examples of the React Native time conversion format tool for your reference. The specific content is as follows:
Class DateUtil {/*** For example: Convert-replace to/* @ param dateString * @ return date */static parserDateString (dateString) at 10:48:46) {if (dateString) {let regEx = new RegExp ("\-", "gi"); let validDateStr = dateString. replace (regEx, "/"); let milliseconds = Date. parse (validDateStr); return new Date (milliseconds) ;}}// timestamp formater time format static formatDate (timestamp, formater) {let date = New Date (); date. setTime (parseInt (timestamp); formater = (formater! = Null )? Formater: 'yyyy-MM-dd hh: mm'; Date. prototype. format = function (fmt) {var o = {"M +": this. getMonth () + 1, // month "d +": this. getDate (), // Day "h +": this. getHours (), // Hour "m +": this. getMinutes (), // minute "s +": this. getSeconds (), // second "q +": Math. floor (this. getMonth () + 3)/3), // quarter "S": this. getMilliseconds () // millisecond}; if (/(y + )/. test (fmt) fmt = fmt. replace (RegExp. $1, (this. getFullYear () + ""). substr (4-R EgExp. $1. length); for (var k in o) {if (new RegExp ("(" + k + ")"). test (fmt) fmt = fmt. replace (RegExp. $1, (RegExp. $1. length = 1 )? (O [k]): ("00" + o [k]). substr ("" + o [k]). length);} return fmt;} return date. format (formater) ;}} export default DateUtil;
External call Method
// Replace-with/or DateUtil. formatDate (timestamp, "yyyy-MM-dd hh: mm: ss ")
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.