“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

how to parse output of new Date().toString()

That format is specified in the Date#toString(). Converts this Date object to a String of the form: dow mon dd hh:mm:ss zzz yyyy So, in SimpleDateFormat pattern terms: EEE MMM dd HH:mm:ss zzz yyyy Unrelated to the problem, I wonder if it wasn’t in first place a bad idea to use Date#toString() instead of SimpleDateFormat#format() … Read more

oracle convert unix epoch time to date

To convert from milliseconds from epoch (assume epoch is Jan 1st 1970): select to_date(‘19700101’, ‘YYYYMMDD’) + ( 1 / 24 / 60 / 60 / 1000) * 1322629200000 from dual; 11/30/2011 5:00:00 AM To convert that date back to milliseconds: select (to_date(’11/30/2011 05:00:00′, ‘MM/DD/YYYY HH24:MI:SS’) – to_date(‘19700101’, ‘YYYYMMDD’)) * 24 * 60 * 60 * … Read more

Convert and format a Date in JSP

In JSP, you’d normally like to use JSTL <fmt:formatDate> for this. You can of course also throw in a scriptlet with SimpleDateFormat, but scriptlets are strongly discouraged since 2003. Assuming that ${bean.date} returns java.util.Date, here’s how you can use it: <%@ taglib prefix=”fmt” uri=”http://java.sun.com/jsp/jstl/fmt” %> … <fmt:formatDate value=”${bean.date}” pattern=”yyyy-MM-dd HH:mm:ss” /> If you’re actually using … Read more

Sqlite convert string to date

As SQLite doesn’t have a date type you will need to do string comparison to achieve this. For that to work you need to reverse the order – eg from dd/MM/yyyy to yyyyMMdd, using something like where substr(column,7)||substr(column,4,2)||substr(column,1,2) between ‘20101101’ and ‘20101130’

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

Where can I find documentation on formatting a date in JavaScript?

I love 10 ways to format time and date using JavaScript and Working with Dates. Basically, you have three methods and you have to combine the strings for yourself: getDate() // Returns the date getMonth() // Returns the month getFullYear() // Returns the year Example: var d = new Date(); var curr_date = d.getDate(); var … Read more