date to string format javascript
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;
}//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();
}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"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 remove element from array in javascript
- Category
- JavaScript
- Title
- include javascript jquery file in html
- Category
- JavaScript
- Title
- iterate through array javascript
- Category
- JavaScript
- Title
- get client timezone offset JavaScript
- Category
- JavaScript
- Title
- angular sumar labels
- Category
- JavaScript
- Title
- fs create or edit file
- Category
- JavaScript
- Title
- edit onclick event
- Category
- JavaScript
- Title
- Bots server count discord js
- Category
- JavaScript
- Title
- how to find id in array javascript
- Category
- JavaScript
- Title
- append img to svg d3 js
- Category
- JavaScript
- Title
- firebase configuration on functions
- Category
- JavaScript
- Title
- form validation react
- Category
- JavaScript
- Title
- ERROR in ./node_modules/tns-core-modules/ui/core/view/view.js Module not found: Error: Can't resolve '@nativescript/core/ui/core/view/view' in '/home/deepali/projects/supersquad-client/node_modules/tns-core-modules/ui/core/view'
- Category
- JavaScript
- Title
- function js
- Category
- JavaScript
- Title
- import axios react
- Category
- JavaScript
- Title
- command to create react app
- Category
- JavaScript
- Title
- html parser javascript
- Category
- JavaScript
- Title
- disable button click jquery
- Category
- JavaScript
- Title
- .includes javascript
- Category
- JavaScript
- Title
- add element to body javascript
- Category
- JavaScript
- Title
- href before onclick js
- Category
- JavaScript
- Title
- angular npm angular material
- Category
- JavaScript
- Title
- how to get value in array object value using for loop in javascript
- Category
- JavaScript
- Title
- how to make a inventory in js
- Category
- JavaScript
- Title
- javascript anagram check
- Category
- JavaScript
- Title
- get element by class
- Category
- JavaScript
- Title
- alert user javascript
- Category
- JavaScript
- Title
- console.log javascript
- Category
- JavaScript
- Title
- async iife
- Category
- JavaScript
- Title
- expo create react native app
- Category
- JavaScript
- Title
- Javascript check if undefinded
- Category
- JavaScript
- Title
- install node modules
- Category
- JavaScript
- Title
- add a route to a buttoin in angular
- Category
- JavaScript
- Title
- create a form and submit it dynamically jquery
- Category
- JavaScript
- Title
- add custom marker in react-mapbox-gl
- Category
- JavaScript
- Title
- how to check if a number is even or odd in javascript
- Category
- JavaScript
- Title
- how to untick a checkbox with javascript
- Category
- JavaScript
- Title
- how to copy to clipboard in react js
- Category
- JavaScript
- Title
- how to verify timestamp format in javascript
- Category
- JavaScript
- Title
- get start of day javascript
- Category
- JavaScript
- Title
- chart.js label word wrap
- Category
- JavaScript
- Title
- javascript call function every second
- Category
- JavaScript
- Title
- autocomplete list angular 8 material
- Category
- JavaScript
- Title
- check if var is array js
- Category
- JavaScript
- Title
- how to add property to object in javascript
- Category
- JavaScript
- Title
- array unique values javascript
- Category
- JavaScript
- Title
- how to turn decimales into percents with javascript
- Category
- JavaScript
- Title
- enzyme check state
- Category
- JavaScript
- Title
- How to create a nested schema in apollo graphql server
- Category
- JavaScript
- Title
- how to fill false into array javascript
- Category
- JavaScript
- Title
- javascript add function to onchange event
- Category
- JavaScript
- Title
- angular flex layout
- Category
- JavaScript
- Title
- import react dom
- Category
- JavaScript
- Title
- javascript check if number
- Category
- JavaScript
- Title
- file input disable open file picker javascript
- Category
- JavaScript
- Title
- how to detect a button click in javascript
- Category
- JavaScript
- Title
- funcao com o botao esc do teclado javascript
- Category
- JavaScript
- Title
- default props react
- Category
- JavaScript
- Title
- how to make @click in router-link vuejs
- Category
- JavaScript
- Title
- Getting the differences between two objects javascript lib
- Category
- JavaScript
- Title
- if (req.url === "/script.js")
- Category
- JavaScript
- Title
- angular rebuild
- Category
- JavaScript
- Title
- how to delete element in list javascript
- Category
- JavaScript
- Title
- how to iterate through an object in javascript
- Category
- JavaScript
- Title
- is undefined javascript
- Category
- JavaScript
- Title
- javascript .split().reverse.join
- Category
- JavaScript
- Title
- array matching
- Category
- JavaScript
- Title
- angular http call caching issue even after no-cache
- Category
- JavaScript
- Title
- form reset jquery
- Category
- JavaScript
- Title
- args discord.js
- Category
- JavaScript
- Title
- find least common multiple javascript
- Category
- JavaScript
- Title
- javascript cahnge colour of strokerect
- Category
- JavaScript
- Title
- html inline javascript
- Category
- JavaScript
- Title
- csv export in react
- Category
- JavaScript
- Title
- find intersection between two object arrays javascript
- Category
- JavaScript
- Title
- how to create a new react native project
- Category
- JavaScript
- Title
- javascript append element to array
- Category
- JavaScript
- Title
- check if object has method javascript
- Category
- JavaScript
- Title
- change text of element js
- Category
- JavaScript
- Title
- how to scroll to an element javascript react
- Category
- JavaScript
- Title
- how to use react components
- Category
- JavaScript
- Title
- hoe verbind je de nodemcu 8266 met adafruit io
- Category
- JavaScript
- Title
- div background image chnage uisng js
- Category
- JavaScript
- Title
- child process spawn python node js
- Category
- JavaScript
- Title
- iterate through nested object javascript
- Category
- JavaScript
- Title
- importing project images in react native
- Category
- JavaScript
- Title
- discord js bot leave voice channel
- Category
- JavaScript
- Title
- how to get the timestamp in javascript
- Category
- JavaScript
- Title
- como criar uam seessão com jsp
- Category
- JavaScript
- Title
- concantene number in js
- Category
- JavaScript
- Title
- angular moment pipe timeAgo
- Category
- JavaScript
- Title
- get month in two digit in javascript date
- Category
- JavaScript
- Title
- How to make string shorter javascript
- Category
- JavaScript
- Title
- hot get access_token instead of url
- Category
- JavaScript
- Title
- javascript addeventlistener
- Category
- JavaScript
- Title
- check if message mentions users discord js
- Category
- JavaScript
- Title
- how to change a string to number in javascript
- Category
- JavaScript
- Title
- javascript check if variable is a jquery object
- Category
- JavaScript
- Title
- convert string with dot or comma as decimal separator to number in javascript
- Category
- JavaScript
- Title
- how to return the number of nodes in a linked list
- Category
- JavaScript