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

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.