Categories
JavaScript Answers

How to include text in middle of date format with Moment.js and JavaScript?

Spread the love

Sometimes, we want to include text in middle of date format with Moment.js and JavaScript.

In this article, we’ll look at how to include text in middle of date format with Moment.js and JavaScript.

How to include text in middle of date format with Moment.js and JavaScript?

To include text in middle of date format with Moment.js and JavaScript, we escape it with square brackets.

For instance, we write

const s = moment().format("MMM. D, YYYY [at] h:mm A z");

to call format with "MMM. D, YYYY [at] h:mm A z" to return a datetime string with ‘at’ between the date and time.

Conclusion

To include text in middle of date format with Moment.js and JavaScript, we escape it with square brackets.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *