0

Can i get DateTime string into desired format. I want to get current Date into this format July 24th. How can i get this format using jquery/javascript?

I know about the Jquery DateTime, but i did't find way to convert this into this July 24th format.

My code -

var CurrentDate = new Date();
CurrentDate.format("MMMM dd");

but this code always give me - July 24. How can i convert into my desired format.

Thanks for help, any help will be appreciable.

Ishan Jain
  • 8,063
  • 9
  • 48
  • 75
  • I think it is not possible, you need to add manually 1st, 2nd,3rd and so on... – Vinit Prajapati Jul 24 '13 at 10:59
  • possible duplicate of [Formatting a date in JavaScript](http://stackoverflow.com/questions/1056728/formatting-a-date-in-javascript) – gvee Jul 24 '13 at 11:01
  • 2
    @gvee you are still not at liberty to check for duplicates. leave that job to ppl with the reputation to do that. Focus your energy to finding answers, rather than duplicates – AnaMaria Jul 24 '13 at 11:03

5 Answers5

1

Use the plugin of jQuery for datetime format.

The plugin is here: jquery-dateFormat.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
1

Test this in jsfiddler here http://jsfiddle.net/Pedro3M/rDW9v/4/

var currentTime = new Date();
var Month=new Array("January", "February", "March","April", "May", "June", "July", "August", "September", "October", "November", "December");
var Suffix=new Array("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th");
var day = currentTime.getDate();
var month = currentTime.getMonth();
if (day % 100 >= 11 && day % 100 <= 13)
  today = day + "th";
else
  today = day + Suffix[day % 10];

alert(Month[month]+" "+ today);
Pedro Monte
  • 235
  • 2
  • 10
0

I may be completely wrong, but I don't know of any jQuery plugins that support adding "rd", "th" etc. to a date. A quick google didn't get me any results.

Here's some pseudo-code to get you started:

var toAppend = 'th';
var day = CurrentDate.getDate();
switch(day){
    case '1':
        toAppend = 'st';
        break;
    case '2':
        toAppend = 'nd';
    //Add the rest of the special cases
}

// If date is July 24
CurrentDate += toAppend;
Thor Jacobsen
  • 8,621
  • 2
  • 27
  • 26
0

Jquery date formatting and a little customization will do the job.

$(document).ready(function(){

 var formattedDate = $.datepicker.formatDate("MM dd", new Date());
 var day = $.datepicker.formatDate("dd", new Date()); 

    day=parseInt(day);

    if(day==1)
        formattedDate+="st";
    else if(day==2)
        formattedDate+="nd";
    else if(day==3)
        formattedDate+="rd";
    else
        formattedDate+="th";

    alert(formattedDate);

});

Include Jquery & Jquery UI library to get this functionality

Check JSFiddle HERE

Aneesh Mohan
  • 1,077
  • 8
  • 17
-1

As mentioned in this Link, You can do it by getting date separately and then combine as you wish. See the link please.

Some Code:

<script type="text/javascript">
<!--

var m_names = new Array("January", "February", "March", 
"April", "May", "June", "July", "August", "September", 
"October", "November", "December");

var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();    
document.write(curr_date + "-" + m_names[curr_month] 
+ "-" + curr_year);
//YOUR FORMAT : (MMMM dd)
document.write(m_names[curr_month]+ ' ' + curr_date);

/* The last two lines above have 
to placed on a single line */

//-->
</script>

Be lucky

Community
  • 1
  • 1
A.Mokhtari
  • 451
  • 5
  • 16
  • I just Edited... I think you have never saw the link yet , as you see in code, you can create your own format. Don't Understand Vote Down :( ... – A.Mokhtari Jul 24 '13 at 11:06