How do you specify the date format used when JAXB marshals xsd:dateTime?

You can use an XmlAdapter to customize how a date type is written to XML. package com.example; import java.text.SimpleDateFormat; import java.util.Date; import javax.xml.bind.annotation.adapters.XmlAdapter; public class DateAdapter extends XmlAdapter<String, Date> { private final SimpleDateFormat dateFormat = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”); @Override public String marshal(Date v) throws Exception { synchronized (dateFormat) { return dateFormat.format(v); } } @Override public … Read more

different result for yyyy-mm-dd and yyyy/mm/dd in javascript when passed to “new Date” [duplicate]

It boils down to how Date.parse() handles the ISO-8601 date format. The date time string may be in ISO 8601 format. For example, “2011-10-10” (just date) or “2011-10-10T14:48:00” (date and time) can be passed and parsed. The UTC time zone is used to interpret arguments in ISO 8601 format that do not contain time zone … Read more

Add ‘decimal-mark’ thousands separators to a number

If you want to add a thousands separator, you can write: >>> ‘{0:,}’.format(1000000) ‘1,000,000’ But it only works in Python 2.7 and above. See format string syntax. In older versions, you can use locale.format(): >>> import locale >>> locale.setlocale(locale.LC_ALL, ”) ‘en_AU.utf8’ >>> locale.format(‘%d’, 1000000, 1) ‘1,000,000’ the added benefit of using locale.format() is that it … Read more

Format file size as MB, GB, etc [duplicate]

public static String readableFileSize(long size) { if(size <= 0) return “0”; final String[] units = new String[] { “B”, “kB”, “MB”, “GB”, “TB” }; int digitGroups = (int) (Math.log10(size)/Math.log10(1024)); return new DecimalFormat(“#,##0.#”).format(size/Math.pow(1024, digitGroups)) + ” ” + units[digitGroups]; } This will work up to 1000 TB…. and the program is short!