Convert between LocalDate and sql.Date [duplicate]

The Java 8 version (and later) of java.sql.Date has built in support for LocalDate, including toLocalDate and valueOf(LocalDate). To convert from LocalDate to java.sql.Date you can use java.sql.Date.valueOf( localDate ); And to convert from java.sql.Date to LocalDate: sqlDate.toLocalDate(); Time zones: The LocalDate type stores no time zone information, while java.sql.Date does. Therefore, when using the … Read more

Encoding conversion in java

You don’t need a library beyond the standard one – just use Charset. (You can just use the String constructors and getBytes methods, but personally I don’t like just working with the names of character encodings. Too much room for typos.) EDIT: As pointed out in comments, you can still use Charset instances but have … Read more

Generate json string from multidimensional array data [duplicate]

Once you have your PHP data, you can use the json_encode function; it’s bundled with PHP since PHP 5.2. In your case, your JSON string represents: a list containing 2 elements each one being an object, containing 2 properties/values In PHP, this would create the structure you are representing: $data = array( (object)array( ‘oV’ => … Read more

Correct way to convert size in bytes to KB, MB, GB in JavaScript

From this: (source) function bytesToSize(bytes) { var sizes = [‘Bytes’, ‘KB’, ‘MB’, ‘GB’, ‘TB’]; if (bytes == 0) return ‘0 Byte’; var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); return Math.round(bytes / Math.pow(1024, i), 2) + ‘ ‘ + sizes[i]; } Note: This is original code, Please use fixed version below. Fixed version, unminified and ES6’ed: (by … Read more