Skip to content

Instantly share code, notes, and snippets.

@twosouth
twosouth / gist:e9e8a0523183ea301232b16af94e9837
Created June 27, 2018 17:42
Calculate duration between two dates
var dt_1 = new Date('2018-06-11 03:10:14 AM'); // create date object 1 June 11, 2018 3:10:14 AM
var dt_2 = new Date('2018-06-11 11:17:23 PM'); // create date object 2 June 11, 2018 11:17:23 PM
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.YEAR) + " Years");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.MONTH) + " Months");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.DAY) + " Days");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.HOUR) + " Hours");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.MINUTE) + " Minutes");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.SECOND) + " Seconds");
dt_1 = new Date('2018-06-11 03:10:14 AM'); // create date object 1 June 11, 2018 3:10:14 AM
dt_2 = new Date('2019-06-19 11:17:23 PM'); // create date object 2 June 19, 2019 11:17:23 PM
@twosouth
twosouth / duration.js
Last active June 27, 2018 18:09
Calculate duration between dates
var dt_1 = new Date('2018-06-11 03:10:14 AM'); // create date object 1 June 11, 2018 3:10:14 AM
var dt_2 = new Date('2018-06-11 11:17:23 PM'); // create date object 2 June 11, 2018 11:17:23 PM
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.YEAR) + " Years");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.MONTH) + " Months");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.DAY) + " Days");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.HOUR) + " Hours");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.MINUTE) + " Minutes");
console.log(Ext.Date.diff(dt_1, dt_2, Ext.Date.SECOND) + " Seconds");
@twosouth
twosouth / MCPSimpleJSON_3.java
Last active June 28, 2018 17:01
JSON Object with JSON Array containing JSON Objects that also contain a JSON Srray
package mcp.json.sample;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class MCPSimpleJSON_3 {
public static void main(String[] args) {
MCPSimpleJSON_3 msj = new MCPSimpleJSON_3();
@twosouth
twosouth / MCPSimpleJSON_2.java
Last active June 28, 2018 17:02
Simple example of creating a JSON Array containing JSON objects
package mcp.json.sample;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class MCPSimpleJSON_2 {
public static void main(String[] args) {
MCPSimpleJSON_2 msj = new MCPSimpleJSON_2();
@twosouth
twosouth / MCPSimpleJSON_1.java
Last active June 28, 2018 17:02
Simple example of creating a JSON object
package mcp.json.sample;
import org.json.simple.JSONObject;
public class MCPSimpleJSON_1 {
public static void main(String[] args) {
MCPSimpleJSON_1 msj = new MCPSimpleJSON_1();
System.out.println(msj.getJson());