format date js
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;
}const t = new Date();
const date = ('0' + t.getDate()).slice(-2);
const month = ('0' + (t.getMonth() + 1)).slice(-2);
const year = t.getFullYear();
const hours = ('0' + t.getHours()).slice(-2);
const minutes = ('0' + t.getMinutes()).slice(-2);
const seconds = ('0' + t.getSeconds()).slice(-2);
const time = `${date}/${month}/${year}, ${hours}:${minutes}:${seconds}`;
output: "27/04/2020, 12:03:03"var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var today = new Date();
console.log(today.toLocaleDateString("en-US")); // 9/17/2016
console.log(today.toLocaleDateString("en-US", options)); // Saturday, September 17, 2016
console.log(today.toLocaleDateString("hi-IN", options)); //usage ex: alert(dateToNiceString(new Date()));
//returns this format: "Oct 23 2019"
function dateToNiceString(myDate){
var month = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",];
return month[myDate.getMonth()]+" "+myDate.getDate()+" "+myDate.getFullYear();
}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
- ckeditor get instance from textarea
- Category
- JavaScript
- Title
- drupal 8 check if current page is node
- Category
- JavaScript
- Title
- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project electronicbookshop: Compilation failure
- Category
- JavaScript
- Title
- how to find the index of a value in an array in javascript
- Category
- JavaScript
- Title
- how to make vue app talk to backend on 8000
- Category
- JavaScript
- Title
- gitignore for angular
- Category
- JavaScript
- Title
- declare function javascript
- Category
- JavaScript
- Title
- Add table row in jQuery
- Category
- JavaScript
- Title
- event listener on parent not on childjavascript
- Category
- JavaScript
- Title
- get current url js
- Category
- JavaScript
- Title
- how to add role in discord.js v12
- Category
- JavaScript
- Title
- AWS SDK for javascript assumerole with proxy
- Category
- JavaScript
- Title
- for(let [key,val] in obj){ messageBody = messageBody.replace("{"+ key + "}",val) }
- Category
- JavaScript
- Title
- event target javascript
- Category
- JavaScript
- Title
- iterate through array js
- Category
- JavaScript
- Title
- If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That will permanently disable this message but you might encounter other issues.
- Category
- JavaScript
- Title
- clear scene\
- Category
- JavaScript
- Title
- function js
- Category
- JavaScript
- Title
- how to use reduce javascript
- Category
- JavaScript
- Title
- how to import jquery in js file
- Category
- JavaScript
- Title
- git empty commit
- Category
- JavaScript
- Title
- adonisjs vscode debugger
- Category
- JavaScript
- Title
- bookshelf insert multiple rows
- Category
- JavaScript
- Title
- convert jquery to string
- Category
- JavaScript
- Title
- discord.js
- Category
- JavaScript
- Title
- boucle for of javascript
- Category
- JavaScript
- Title
- download image in nodejs
- Category
- JavaScript
- Title
- difference between React Native and React
- Category
- JavaScript
- Title
- display none after hover
- Category
- JavaScript
- Title
- chart js rotating the x axis labels
- Category
- JavaScript
- Title
- how to Write a program that simulates a coin toss using random method of Javascript Math class
- Category
- JavaScript
- Title
- clone a JavaScript object
- Category
- JavaScript
- Title
- add readonly attribute jquery
- Category
- JavaScript
- Title
- arrow function javascript ie11
- Category
- JavaScript
- Title
- add a route to a buttoin in angular
- Category
- JavaScript
- Title
- for of loop syntax javascript
- Category
- JavaScript
- Title
- how to stop user from clicking outside alert box js
- Category
- JavaScript
- Title
- combine values of address line 1 and address line 2 javascript
- Category
- JavaScript
- Title
- javascript all type of data
- Category
- JavaScript
- Title
- cb() never called! npm ERR! This is an error with npm itself.
- Category
- JavaScript
- Title
- how to get the next item in map() js
- Category
- JavaScript
- Title
- angular open poort in network
- Category
- JavaScript
- Title
- is javascript good
- Category
- JavaScript
- Title
- angular delete from array by name
- Category
- JavaScript
- Title
- hover jquery
- Category
- JavaScript
- Title
- const{}=
- Category
- JavaScript
- Title
- angular file upload app with django
- Category
- JavaScript
- Title
- javascript check empty object
- Category
- JavaScript
- Title
- How to check if a member has a role discord.js
- Category
- JavaScript
- Title
- how to delete an element from an array in javascript
- Category
- JavaScript
- Title
- console.log in jsx
- Category
- JavaScript
- Title
- How can I refresh a page with jQuery
- Category
- JavaScript
- Title
- how to make a circle in js
- Category
- JavaScript
- Title
- angular ng-click toggle class
- Category
- JavaScript
- Title
- insert into mongodb node js
- Category
- JavaScript
- Title
- 2gis nuxt
- Category
- JavaScript
- Title
- async await arrow function
- Category
- JavaScript
- Title
- assign values to a table from javascript in VF page
- Category
- JavaScript
- Title
- how to get nth fibonacci javascript
- Category
- JavaScript
- Title
- angular list contains property
- Category
- JavaScript
- Title
- fizz buzz javascript
- Category
- JavaScript
- Title
- headroom js react
- Category
- JavaScript
- Title
- closure javascript
- Category
- JavaScript
- Title
- how to make a var and sprite in javascript
- Category
- JavaScript
- Title
- componentWillUnmount functional component for asynchronous requests
- Category
- JavaScript
- Title
- error duplicate resources react native
- Category
- JavaScript
- Title
- interaction js drag anddrop
- Category
- JavaScript
- Title
- how to initialize an array in javascript
- Category
- JavaScript
- Title
- erela client userID
- Category
- JavaScript
- Title
- boucle for in js
- Category
- JavaScript
- Title
- how to access clipboard via js
- Category
- JavaScript
- Title
- chrome add a bookmark that appends to current url
- Category
- JavaScript
- Title
- get selected option value
- Category
- JavaScript
- Title
- how to import npm packages in node.js?
- Category
- JavaScript
- Title
- discord.js reply to message
- Category
- JavaScript
- Title
- javascript check if variable exists
- Category
- JavaScript
- Title
- backbone js event listener
- Category
- JavaScript
- Title
- event listener javascript
- Category
- JavaScript
- Title
- javascript check if argument is passed
- Category
- JavaScript
- Title
- Javascript check if undefined
- Category
- JavaScript
- Title
- express and node
- Category
- JavaScript
- Title
- javascript ajax request
- Category
- JavaScript
- Title
- fixed header on scroll vuejs
- Category
- JavaScript
- Title
- how to wait for an exec command to fininsh in nodejs
- Category
- JavaScript
- Title
- busca binária em javascript
- Category
- JavaScript
- Title
- .filter js
- Category
- JavaScript
- Title
- go to another page using javascript
- Category
- JavaScript
- Title
- convert object to array javascript
- Category
- JavaScript
- Title
- fromjson method convert integer to double
- Category
- JavaScript
- Title
- add dynamic value to id attribute in angular 8
- Category
- JavaScript
- Title
- discord js delete message after time
- Category
- JavaScript
- Title
- javascript array flatten
- Category
- JavaScript
- Title
- create react app in existing folder
- Category
- JavaScript
- Title
- injected stylesheet remove
- Category
- JavaScript
- Title
- add bootstrap to gatsby
- Category
- JavaScript
- Title
- heroku failed to run files from static folder in node
- Category
- JavaScript
- Title
- dotenv
- Category
- JavaScript
- Title
- express() vs express.router()
- Category
- JavaScript
- Title
- javascript add new array element to start of array
- Category
- JavaScript
- Title
- javascript add to object
- Category
- JavaScript