format date javascript
JavaScript
const d = new Date('2010-08-05')
const ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(d)
const mo = new Intl.DateTimeFormat('en', { month: 'short' }).format(d)
const da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(d)
console.log(`${da}-${mo}-${ye}`)//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();
}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 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 consoleconst 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"
Also in JavaScript:
- Title
- how to transpose json data
- Category
- JavaScript
- Title
- create array from htmlcollection
- Category
- JavaScript
- Title
- insert item into array specific index javascript
- Category
- JavaScript
- Title
- javascript codegolf round
- Category
- JavaScript
- Title
- empty textarea using jquery
- Category
- JavaScript
- Title
- export to logs to elasticsearch node from fluend container k8s
- Category
- JavaScript
- Title
- array dia semana javascript
- Category
- JavaScript
- Title
- How to get row index and cellindex together in javascript
- Category
- JavaScript
- Title
- how do i backspace from javascript calculator
- Category
- JavaScript
- Title
- javascript class constructor
- Category
- JavaScript
- Title
- Embed Example Discord.js
- Category
- JavaScript
- Title
- how to run mocha tests on asynchronous functions in script
- Category
- JavaScript
- Title
- Bots latency discord js
- Category
- JavaScript
- Title
- assign this value or if it is undefined this other value javascript
- Category
- JavaScript
- Title
- disregard empty field in array
- Category
- JavaScript
- Title
- javascript class inheritance
- Category
- JavaScript
- Title
- get looping in jquery
- Category
- JavaScript
- Title
- convert milliseconds to minutes and seconds javascript
- Category
- JavaScript
- Title
- jacvascript parse float
- Category
- JavaScript
- Title
- how to wait for an exec command to fininsh in nodejs
- Category
- JavaScript
- Title
- discord.js reply to message
- Category
- JavaScript
- Title
- for in loops javascript
- Category
- JavaScript
- Title
- javacript getHTTPURL
- Category
- JavaScript
- Title
- How to include JSPs file from another folder
- Category
- JavaScript
- Title
- iterate over array of object javascript and access the properties
- Category
- JavaScript
- Title
- $pull mongoose
- Category
- JavaScript
- Title
- copy text on button click in jquery
- Category
- JavaScript
- Title
- how to send enter event to input field jquery
- Category
- JavaScript
- Title
- how to validate the textbox using jquery
- Category
- JavaScript
- Title
- javascript check if variable is object
- Category
- JavaScript
- Title
- javascript change element id
- Category
- JavaScript
- Title
- hello
- Category
- JavaScript
- Title
- how to change tag name in js html
- Category
- JavaScript
- Title
- how to pretty formatjson value on terminal ruby
- Category
- JavaScript
- Title
- check the doc name in javascript
- Category
- JavaScript
- Title
- check if file exists javascript
- Category
- JavaScript
- Title
- how to make a clock in html/javascript
- Category
- JavaScript
- Title
- exercism.io bob solution
- Category
- JavaScript
- Title
- javascript array find highest value of array of objects by key
- Category
- JavaScript
- Title
- how to disable cash through get request in angular
- Category
- JavaScript
- Title
- how to scroll to an element javascript react
- Category
- JavaScript
- Title
- how to enable click copy function using js
- Category
- JavaScript
- Title
- javascript async fetch file html
- Category
- JavaScript
- Title
- how to access clipboard via js
- Category
- JavaScript
- Title
- how to displayan inteiger to a tenth in javascript
- Category
- JavaScript
- Title
- discord.js command prompt notification
- Category
- JavaScript
- Title
- get id of clicked element javascript
- Category
- JavaScript
- Title
- function redirect javascript
- Category
- JavaScript
- Title
- inline style boarder radius jsx
- Category
- JavaScript
- Title
- how to make a stopwatch using js
- Category
- JavaScript
- Title
- blob to text javascript
- Category
- JavaScript
- Title
- convert 24 hour to 12 hour moment js
- Category
- JavaScript
- Title
- javascript canvas
- Category
- JavaScript
- Title
- hoe verbind je de nodemcu 8266 met adafruit io
- Category
- JavaScript
- Title
- javascript ajax
- Category
- JavaScript
- Title
- javascript canvas beziercurveto
- Category
- JavaScript
- Title
- angular @Input()
- Category
- JavaScript
- Title
- get href attribute javascript
- Category
- JavaScript
- Title
- how to add an array to another array in javascript
- Category
- JavaScript
- Title
- discord.js wait seconds
- Category
- JavaScript
- Title
- find particular object from array in js
- Category
- JavaScript
- Title
- javascript check if file exists in folder
- Category
- JavaScript
- Title
- how to log to the console javascript
- Category
- JavaScript
- Title
- clear the command prompt node
- Category
- JavaScript
- Title
- how to set state when change viewport react
- Category
- JavaScript
- Title
- javascript change class of item
- Category
- JavaScript
- Title
- get contents between tags javascript
- Category
- JavaScript
- Title
- how to check if local storage variable exists in javascript
- Category
- JavaScript
- Title
- angular check if control has required validator
- Category
- JavaScript
- Title
- how to count the rows of gridview in asp.net using jquery
- Category
- JavaScript
- Title
- ignore node modules
- Category
- JavaScript
- Title
- get string value of boolean javascript
- Category
- JavaScript
- Title
- create many items from an array to canvas
- Category
- JavaScript
- Title
- delete session javascript
- Category
- JavaScript
- Title
- code array javascript
- Category
- JavaScript
- Title
- javascript class
- Category
- JavaScript
- Title
- javascript check if number is hexadecimal
- Category
- JavaScript
- Title
- devextreme custom field
- Category
- JavaScript
- Title
- how to use rest api with vision api in react
- Category
- JavaScript
- Title
- Email validation using javascript
- Category
- JavaScript
- Title
- cypress backspace
- Category
- JavaScript
- Title
- (function (g, d, a) {})(window, document, jQuery);
- Category
- JavaScript
- Title
- How do I check if an element is hidden in jQuery?
- Category
- JavaScript
- Title
- how to check if item is in list js
- Category
- JavaScript
- Title
- how to check if object is undefined in javascript
- Category
- JavaScript
- Title
- array map javascript
- Category
- JavaScript
- Title
- javascript check for null variables
- Category
- JavaScript
- Title
- Discord.js Basics
- Category
- JavaScript
- Title
- javascript clear localstorage
- Category
- JavaScript
- Title
- cre&atRefs react js
- Category
- JavaScript
- Title
- cypress disabled
- Category
- JavaScript
- Title
- javascript add to array
- Category
- JavaScript
- Title
- get messages by id discord.js
- Category
- JavaScript
- Title
- javascript check empty object
- Category
- JavaScript
- Title
- how to count occurrences of each character in string in javascript
- Category
- JavaScript
- Title
- check data type in js
- Category
- JavaScript
- Title
- javascript Arranging Coins
- Category
- JavaScript
- Title
- enter ascii code in javascript
- Category
- JavaScript
- Title
- how to check if window size of browser s changed javascript
- Category
- JavaScript
- Title
- disable mixed content via javascript
- Category
- JavaScript