How to format a JavaScript date
JavaScript
//usage ex: alert(dateToNiceString(new Date()));
//returns this format: "Oct 23 2019 1:09pm"
function dateToNiceString(myDate){
var month=new Array();
month[0]="Jan";
month[1]="Feb";
month[2]="Mar";
month[3]="Apr";
month[4]="May";
month[5]="Jun";
month[6]="Jul";
month[7]="Aug";
month[8]="Sep";
month[9]="Oct";
month[10]="Nov";
month[11]="Dec";
var hours = myDate.getHours();
var minutes = myDate.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12;
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ampm;
return month[myDate.getMonth()]+" "+myDate.getDate()+" "+myDate.getFullYear()+" "+strTime;
}function formatDate(date) {
var monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
];
var day = date.getDate();
var monthIndex = date.getMonth();
var year = date.getFullYear();
return day + ' ' + monthNames[monthIndex] + ' ' + year;
}
console.log(formatDate(new Date())); // show current date-time in console
Also in JavaScript:
- Title
- how to change port in next js
- Category
- JavaScript
- Title
- how to get tomorrow date in javascript
- Category
- JavaScript
- Title
- expo app.json
- Category
- JavaScript
- Title
- html to jsx
- Category
- JavaScript
- Title
- how to concatenate strings javascript
- Category
- JavaScript
- Title
- get number right of the dot length javascript
- Category
- JavaScript
- Title
- drupal 8 check if current page is node
- Category
- JavaScript
- Title
- how to sort array least to greatest javascript
- Category
- JavaScript
- Title
- is var is not blank then display value in javascript
- Category
- JavaScript
- Title
- flatten nested object js
- Category
- JavaScript
- Title
- check multiple ifield if it's blank in jquery
- Category
- JavaScript
- Title
- fetch get data js
- Category
- JavaScript
- Title
- how to check chrome version in js
- Category
- JavaScript
- Title
- angular cli skip-tests
- Category
- JavaScript
- Title
- is object js
- Category
- JavaScript
- Title
- changing columns for table requires doctrine dbal install doctrine/dbal
- Category
- JavaScript
- Title
- express js sample project
- Category
- JavaScript
- Title
- javascript array to comma separated string
- Category
- JavaScript
- Title
- if str contains jquery
- Category
- JavaScript
- Title
- add a route to a buttoin in angular
- Category
- JavaScript
- Title
- How to uninstall npm modules in node js?
- Category
- JavaScript
- Title
- angular build production
- Category
- JavaScript
- Title
- How to check whether a checkbox is checked in jQuery?
- Category
- JavaScript
- Title
- create dice game javascript
- Category
- JavaScript
- Title
- convert json to object jackson
- Category
- JavaScript
- Title
- how to copy to clipboard in react js
- Category
- JavaScript
- Title
- how to use custom stylesheets express node
- Category
- JavaScript
- Title
- functions in map javascript
- Category
- JavaScript
- Title
- columndefs in datatable not working while setting width jquery
- Category
- JavaScript
- Title
- how to attach javascript to html
- Category
- JavaScript
- Title
- getFullYear within moment in angular
- Category
- JavaScript
- Title
- console.log in jsx
- Category
- JavaScript
- Title
- abstraction in javascript
- Category
- JavaScript
- Title
- add countdown timer to javascript quiz
- Category
- JavaScript
- Title
- changing attributes using javascript
- Category
- JavaScript
- Title
- how to debug javascript
- Category
- JavaScript
- Title
- Add table row in jQuery
- Category
- JavaScript
- Title
- how to add multiple comment in react
- Category
- JavaScript
- Title
- how to import jquery in js file
- Category
- JavaScript
- Title
- add dynamic value to id attribute in angular 8
- Category
- JavaScript
- Title
- expo create react native app
- Category
- JavaScript
- Title
- javascript array concat spread operator
- Category
- JavaScript
- Title
- classList has class
- Category
- JavaScript
- Title
- enter event in jquery
- Category
- JavaScript
- Title
- how to delete a variable in js
- Category
- JavaScript
- Title
- facebook integration in node.js
- Category
- JavaScript
- Title
- angularjs socket.io
- Category
- JavaScript
- Title
- check if number appears odd number of times in array javascript
- Category
- JavaScript
- Title
- Find parent and child from array javascript
- Category
- JavaScript
- Title
- bind and unbind jquery validation
- Category
- JavaScript
- Title
- get all data attributes jquery from multiple elements
- Category
- JavaScript
- Title
- how to add text to h2 with jquery
- Category
- JavaScript
- Title
- clone an object in javascript
- Category
- JavaScript
- Title
- concantene number in js
- Category
- JavaScript
- Title
- axios set authorization header
- Category
- JavaScript
- Title
- async await promise all javascript
- Category
- JavaScript
- Title
- array chunk javascript
- Category
- JavaScript
- Title
- how to stringify json in js
- Category
- JavaScript
- Title
- get current directory vbscript
- Category
- JavaScript
- Title
- blob to text javascript
- Category
- JavaScript
- Title
- how to extract values from array in javascript
- Category
- JavaScript
- Title
- how to redirect react router from the app components
- Category
- JavaScript
- Title
- add multiple images inside the DOM js
- Category
- JavaScript
- Title
- javascript check if number is hexadecimal
- Category
- JavaScript
- Title
- find duplicates in array of objects javascript
- Category
- JavaScript
- Title
- angular file upload app with django
- Category
- JavaScript
- Title
- get value from textbox in vanilla javascript
- Category
- JavaScript
- Title
- firestore update map
- Category
- JavaScript
- Title
- AWS SDK for javascript assumerole with proxy
- Category
- JavaScript
- Title
- como utilizar jquery
- Category
- JavaScript
- Title
- how to link javascript to html
- Category
- JavaScript
- Title
- async await catch error
- Category
- JavaScript
- Title
- ajax file upload jquery
- Category
- JavaScript
- Title
- javascript change webpage title
- Category
- JavaScript
- Title
- get only last 2 digit of year in javascript
- Category
- JavaScript
- Title
- google sign in in firebase react
- Category
- JavaScript
- Title
- compare two arrays
- Category
- JavaScript
- Title
- cascading dropdown for forms react
- Category
- JavaScript
- Title
- iterate through list javascript
- Category
- JavaScript
- Title
- ajax .put
- Category
- JavaScript
- Title
- get location from brwoser react
- Category
- JavaScript
- Title
- javascript change url without reload
- Category
- JavaScript
- Title
- how to get the value in a tag in react
- Category
- JavaScript
- Title
- javascript access property values list of objects
- Category
- JavaScript
- Title
- how to find length of array in javascript without using length method
- Category
- JavaScript
- Title
- javascript array flatten
- Category
- JavaScript
- Title
- headroom js react
- Category
- JavaScript
- Title
- cannot read property 'props' of undefined react redux functional component
- Category
- JavaScript
- Title
- change bloodhound remote dynamically
- Category
- JavaScript
- Title
- array.filter in js
- Category
- JavaScript
- Title
- install vue-cli
- Category
- JavaScript
- Title
- JavaScript banner
- Category
- JavaScript
- Title
- find last element in array javascript
- Category
- JavaScript
- Title
- jason rpc reactjs
- Category
- JavaScript
- Title
- args discord.js
- Category
- JavaScript
- Title
- get attribute value jquery href
- Category
- JavaScript
- Title
- get last item in array js
- Category
- JavaScript
- Title
- () = javascript
- Category
- JavaScript
- Title
- add select option jquery
- Category
- JavaScript
- Title
- html get class property
- Category
- JavaScript