close

How to get am pm from the date time string using moment js

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to get am pm from the date time string using moment js in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to get am pm from the date time string using moment js ?

  1. How to get am pm from the date time string using moment js ?

    to get am pm from the date time string using moment js
    you will get the time without specifying the date format. convert the string to date using Date object
    var myDate = new Date('Mon 03-Jul-2017, 06:00 PM');

  2. How to get am pm from the date time string using moment js ?

    to get am pm from the date time string using moment js
    you will get the time without specifying the date format. convert the string to date using Date object
    var myDate = new Date('Mon 03-Jul-2017, 06:00 PM');

Method 1

You are using the wrong format tokens when parsing your input. You should use ddd for an abbreviation of the name of day of the week, DD for day of the month, MMM for an abbreviation of the month’s name, YYYY for the year, hh for the 1-12 hour, mm for minutes and A for AM/PM. See moment(String, String) docs.

Method 2


you will get the time without specifying the date format. convert the string to date using Date object

var myDate = new Date('Mon 03-Jul-2017, 06:00 PM');

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment