Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here you go</p> <pre><code>var myDate = new Date("February 04, 2011 19:00:00"); var hr = myDate.getHours(); var convHrs = ""; var ampmSwitch = ""; ampmSwitch = (hr &gt; 12)? "PM":"AM"; convHrs = (hr &gt;12)? hr-12:hr; // Build back the Date / time using getMonth/ getFullYear and getDate and other functions on the myDate object. Enclose it inside a func and there you got the working 12 hrs converter ;) </code></pre> <p>And here's the converter func for yas ;) Happy coding!!</p> <pre><code>function convertTo12Hrs(yourDateTime){ var myDate = new Date(yourDateTime); var dtObject = new Object(); var monthsCollection = {0:"January", 1:"February",2:"March",3:"April",4:"May",5:"June",6:"July",7:"August",8:"September",9:"October",10:"November",11:"December"}; dtObject.year = myDate.getFullYear(); dtObject.month = monthsCollection[myDate.getMonth()]; dtObject.day = (myDate.getDate()&lt;10)?"0"+myDate.getDate():myDate.getDate(); dtObject.minutes = (myDate.getMinutes() &lt; 10)? "0"+myDate.getMinutes():myDate.getMinutes(); dtObject.seconds = (myDate.getSeconds() &lt; 10)? "0"+myDate.getSeconds():myDate.getSeconds(); // Check if hours are greater than 12? Its PM dtObject.ampmSwitch = (myDate.getHours() &gt; 12)? "PM":"AM"; // Convert the hours dtObject.hour = (myDate.getHours() &gt; 12)?myDate.getHours()-12:myDate.getHours(); // Add the 0 as prefix if its less than 10 dtObject.hour = (dtObject.hour &lt; 10)? "0"+dtObject.hour:dtObject.hour; // Format back the string as it was or return the dtObject object or however you like. I am returning the object here return dtObject; } </code></pre> <p>invoke it like convertTo12Hrs("February 04, 2011 19:00:00"); it will return you the object, which in turn you can use to format back your datetime string as you fancy... </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload