1

I am using Shield UI Date picker for capturing DOB, I am facing problem in formatting the selected date. The JavaScript code I had used is shown below

$("#dobPicker").shieldDatePicker({
    openOnFocus: true,
    format: "{0:dd/MM/yyyy}",
    textTemplate: "{0:dd/MM/yyyy}",
    parseFormats: ["dd/MM/yyyy"],
    max: new Date(),
    events: {
        change: function(e) {
            var dobVal = $("#dobPicker").swidget().value();
            alert(dobVal);
        }
    }
});

And the output I got is in the below format

Thu Aug 20 2015 00:00:00 GMT+0530 (India Standard Time)

But I require an out put in dd/MM/yyyy format

Could you help me to solve this?

Thanks in advance :)

  • possible duplicate of http://stackoverflow.com/questions/1328025/jquery-ui-datepicker-change-date-format – Abhishek Ghosh Aug 22 '15 at 15:18
  • 1
    @AbhishekGhosh I was searching for any inbuilt way to get that formatted value from my plugin(Shield UI). Thanks for the reply :) – Sreejith SG Aug 24 '15 at 07:18

2 Answers2

0

Moment you can use. This is great library for handling date. CDN LINK for your use or you can download also.

var dobVal = new Date();
console.log(dobVal);//output Sat Aug 22 2015 20:24:10 GMT+0530 (IST)
var formatted = moment(dobVal).format("DD/MM/YYYY");
console.log(formatted);//output 22/08/2015

DEMO

Manwal
  • 23,450
  • 12
  • 63
  • 93
  • Thanks for the reply :) I was searching for is there any inbuilt method to get that formatted value from the plugin Shield UI – Sreejith SG Aug 24 '15 at 07:22
0

You can parse the date as a standard date and format it any way you want.

Once you get the value, you can parse it and format it as needed. This is demonstrated here.