How to format a Date in MM/dd/yyyy HH:mm:ss format in JavaScript? [duplicate]

[Addendum 12/2022]: Here’s a library to format dates using Intl.DateTimeFormat. Try something like this var d = new Date, dformat = [d.getMonth()+1, d.getDate(), d.getFullYear()].join(“https://stackoverflow.com/”)+’ ‘+ [d.getHours(), d.getMinutes(), d.getSeconds()].join(‘:’); If you want leading zero’s for values < 10, use this number extension Number.prototype.padLeft = function(base,chr){ var len = (String(base || 10).length – String(this).length)+1; return len > … Read more

java.util.Date format conversion yyyy-mm-dd to mm-dd-yyyy

Date is a container for the number of milliseconds since the Unix epoch ( 00:00:00 UTC on 1 January 1970). It has no concept of format. Java 8+ LocalDateTime ldt = LocalDateTime.now(); System.out.println(DateTimeFormatter.ofPattern(“MM-dd-yyyy”, Locale.ENGLISH).format(ldt)); System.out.println(DateTimeFormatter.ofPattern(“yyyy-MM-dd”, Locale.ENGLISH).format(ldt)); System.out.println(ldt); Outputs… 05-11-2018 2018-05-11 2018-05-11T17:24:42.980 Java 7- You should be making use of the ThreeTen Backport Original Answer For … Read more

Java date format – including additional characters

Sure, with the SimpleDateFormat you can include literal strings: Within date and time pattern strings, unquoted letters from ‘A’ to ‘Z’ and from ‘a’ to ‘z’ are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes (‘) to avoid interpretation. “”” represents a single … Read more

“Java DateFormat is not threadsafe” what does this leads to?

Let’s try it out. Here is a program in which multiple threads use a shared SimpleDateFormat. Program: public static void main(String[] args) throws Exception { final DateFormat format = new SimpleDateFormat(“yyyyMMdd”); Callable<Date> task = new Callable<Date>(){ public Date call() throws Exception { return format.parse(“20101022”); } }; //pool with 5 threads ExecutorService exec = Executors.newFixedThreadPool(5); List<Future<Date>> … Read more

Rails formatting date

Use Model.created_at.strftime(“%FT%T”) where, %F – The ISO 8601 date format (%Y-%m-%d) %T – 24-hour time (%H:%M:%S) Following are some of the frequently used useful list of Date and Time formats that you could specify in strftime method: Date (Year, Month, Day): %Y – Year with century (can be negative, 4 digits at least) -0001, 0000, … Read more

How to format date in angularjs

Angular.js has a built-in date filter. demo // in your controller: $scope.date=”20140313T00:00:00″; // in your view, date property, filtered with date filter and format ‘MM/dd/yyyy’ <p ng-bind=”date | date:’MM/dd/yyyy'”></p> // produces 03/13/2014 You can see the supported date formats in the source for the date filter. edit: If you’re trying to get the correct format … Read more