Share the React Native time conversion format tool class, reactnative

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.