Converts the date from the moment.js format to a java.util.Date.
343158
@Override
	public Object getConvertedValue(FacesContext context, Object submittedValue) throws ConverterException {
		if (submittedValue == null) {
			return null;
		}

		String val = (String) submittedValue;
		// If the Trimmed submitted value is empty, return null
		if (val.trim().length() == 0) {
			return null;
		}

		Converter converter = this.getConverter();

		// If the user supplied a converter, use it
		if (converter != null) {
			return converter.getAsObject(context, this, val);
		}
		// Else we use our own converter
		Locale sloc = BsfUtils.selectLocale(context.getViewRoot().getLocale(), this.getLocale(), this);
		String momentJSFormat = BsfUtils.selectMomentJSDateTimeFormat(sloc, this.getFormat(), this.isShowDate(),
				this.isShowTime());
		String javaFormat = LocaleUtils.momentToJavaFormat(momentJSFormat);

		Calendar cal = Calendar.getInstance(sloc);
		SimpleDateFormat format = new SimpleDateFormat(javaFormat, sloc);
		format.setTimeZone(cal.getTimeZone());

		try {
			cal.setTime(format.parse(val));

			return cal.getTime();
		} catch (ParseException e) {

			// FIRST STEP GONE: TRY THE AUTO-PARSER
			try {
				cal.setTime(LocaleUtils.autoParseDateFormat(val));
				return cal.getTime();
			} catch (Exception pe) {
				this.setValid(false);
				throw new ConverterException(BsfUtils.getMessage("javax.faces.converter.DateTimeConverter.DATE", val,
						javaFormat, BsfUtils.getLabel(context, this)));
			}
		}
	}
835325
def format(date, now=None, locale='en'):
    '''
    
    '''
    if not isinstance(date, timedelta):
        if now is None:
            now = datetime.now()
        date = parser.parse(date)
        now = parser.parse(now)

        if date is None:
            raise ParameterUnvalid('the parameter `date` should be datetime '
                                   '/ timedelta, or datetime formated string.')
        if now is None:
            raise ParameterUnvalid('the parameter `now` should be datetime, '
                                   'or datetime formated string.')
        date = now - date
    # the gap sec
    diff_seconds = int(total_seconds(date))

    # is ago or in
    ago_in = 0
    if diff_seconds < 0:
        ago_in = 1  # date is later then now, is the time in future
        diff_seconds *= -1  # chango to positive

    tmp = 0
    i = 0
    while i < SEC_ARRAY_LEN:
        tmp = SEC_ARRAY[i]
        if diff_seconds >= tmp:
            i += 1
            diff_seconds /= tmp
        else:
            break
    diff_seconds = int(diff_seconds)
    i *= 2

    if diff_seconds > (i == 0 and 9 or 1):
        i += 1

    if locale is None:
        locale = DEFAULT_LOCALE

    tmp = timeago_template(locale, i, ago_in)
    if hasattr(tmp, '__call__'):
        tmp = tmp(diff_seconds)
    return '%s' in tmp and tmp % diff_seconds or tmp
1255505
function getUTCTime(modelValue) {
      var tempDate = new Date()
      if (modelValue) {
        var tempMoment = getMoment(modelValue)
        if (tempMoment.isValid()) {
          tempDate = tempMoment.toDate()
        } else {
          throw new Error('Invalid date: ' + modelValue)
        }
      }
      return tempDate.getTime() - (tempDate.getTimezoneOffset() * 60000)
    }
1285375
public static String selectJavaDateTimeFormatFromMomentJSFormatOrDefault(Locale locale, String momentJSFormat, boolean withDate, boolean withTime) {
		if (momentJSFormat == null) {
			String dateFormat = "";
			if (withDate) {
				dateFormat = ((SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale)).toPattern();
			}
			String timeFormat = "";
			if (withTime) {
				timeFormat = ((SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.MEDIUM, locale)).toPattern();
			}
			// Since DateFormat.SHORT is silly, return a smart format
			if (dateFormat.equals("M/d/yy")) {
				dateFormat = "MM/dd/yyyy";
			}
			else if (dateFormat.equals("d/M/yy")) {
				dateFormat = "dd/MM/yyyy";
			}
			return (dateFormat + " " + timeFormat).trim();
		} else {
			return LocaleUtils.momentToJavaFormat(momentJSFormat);
		}
	}
1244835
function convertTime(value, fromUnit, toUnit)
{
    if(fromUnit != toUnit && value !== 0)
    {
        return value * (toUnit == 's'? 0.001 : 1000);
    }
    return value;
}
763925
function(json) {
      
      var r = function(o) {
          Object.keys(o).forEach(function(v, i) {

              if (o[v] !== null && typeof o[v] === 'object' && o[v].hasOwnProperty('$date')) {                
                  o[v] = moment(o[v]['$date']).toDate();
                  return;
              }
              if (o[v] !== null && typeof o[v] === 'object') return r(o[v])
          })
       }

       r(json);

       return json;
  }
504326
def _datetime_to_utc(self, dt):
        """"""

        if not dt.tzinfo:
            dt = dt.replace(tzinfo=tz.gettz())
        return dt.astimezone(tz.gettz('UTC'))
1144485
private static Calendar toCalendar(Date self) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(self);
        return cal;
    }
183386
public static String selectMomentJSDateTimeFormat(Locale locale, String momentJSFormat, boolean withDate, boolean withTime) {
		if (momentJSFormat == null) {
			String dateFormat = "";
			if (withDate) {
				dateFormat = ((SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale)).toPattern();
			}
			String timeFormat = "";
			if (withTime) {
				timeFormat = ((SimpleDateFormat)DateFormat.getTimeInstance(DateFormat.MEDIUM, locale)).toPattern();
			}
			// Since DateFormat.SHORT is silly, return a smart format
			if (dateFormat.equals("M/d/yy")) {
				dateFormat = "MM/dd/yyyy";
			}
			else if (dateFormat.equals("d/M/yy")) {
				dateFormat = "dd/MM/yyyy";
			}
			String result = LocaleUtils.javaToMomentFormat((dateFormat + " " + timeFormat).trim());
//			System.out.println(result);
			return result;
		} else {
			return momentJSFormat;
		}
	}
1247801
public static Date convertToDate(Object obj) {
		if (obj == null)
			return null;
		if (obj instanceof Date)
			return (Date) obj;
		if (obj instanceof Number)
			return new Date(((Number)obj).longValue());
		if (obj instanceof String) {
			StringTokenizer st = new StringTokenizer((String) obj, " -/:,.+");
			String s1 = "";
			if (!st.hasMoreTokens())
				return null;
			s1 = st.nextToken();
			if (s1.length() == 4 && Character.isDigit(s1.charAt(0)))
				return getYYYYMMDD(st, s1);
			// skip Day if present.
			if (daysTable.containsKey(s1)) {
				if (!st.hasMoreTokens())
					return null;
				s1 = st.nextToken();
			}
			if (monthsTable.containsKey(s1))
				return getMMDDYYYY(st, s1);

			if (Character.isDigit(s1.charAt(0)))
				return getDDMMYYYY(st, s1);
			return null;
		}
		throw new RuntimeException("Primitive: Can not convert " + obj.getClass().getName() + " to int");
	}
1143035
public Date toDate() {
    long secondsInMilliseconds = TimeUnit.SECONDS.toMillis(this.seconds);
    long nanosInMilliseconds = TimeUnit.NANOSECONDS.toMillis(this.nanos);
    return new Date(secondsInMilliseconds + nanosInMilliseconds);
  }
792092
function formatDate( date ) {

	var dateString = '';

	date = new Date( date );

	dateString = date.getMonth() + 1;
	dateString += '/';
	dateString += date.getDate();
	dateString += '/';
	dateString += date.getFullYear();

	return dateString;
}
1059728
def render_date(date, tz=pytz.utc, fmt=_FULL_OUTPUT_FORMAT):
    """"""
    local = date.astimezone(tz)
    ts = __date_to_millisecond_ts(date)
    return fmt.format(
            ts=ts,
            utc=date.strftime(_DATE_FORMAT),
            millis=ts % 1000,
            utc_tz=date.strftime(_TZ_FORMAT),
            local=local.strftime(_DATE_FORMAT),
            local_tz=local.strftime(_TZ_FORMAT),
            delta=render_delta_from_now(date))
935474
public static java.util.Date toJavaUtilDate(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    // Calender.MONTH starts from 0 while G C date starts from 1
    cal.set(date.year, date.month - 1, date.dayOfMonth);
    return cal.getTime();
  }
1340455
def string_to_date(value):
    
    if isinstance(value, datetime.date):
        return value

    return dateutil.parser.parse(value).date()
208549
function parseDate(s, ignoreTimezone) { // ignoreTimezone defaults to true
	if (typeof s == 'object') { // already a Date object
		return s;
	}
	if (typeof s == 'number') { // a UNIX timestamp
		return new Date(s * 1000);
	}
	if (typeof s == 'string') {
		if (s.match(/^\d+(\.\d+)?$/)) { // a UNIX timestamp
			return new Date(parseFloat(s) * 1000);
		}
		if (ignoreTimezone === undefined) {
			ignoreTimezone = true;
		}
		return parseISO8601(s, ignoreTimezone) || (s ? new Date(s) : null);
	}
	// TODO: never return invalid dates (like from new Date(<string>)), return null instead
	return null;
}
996647
function formatTime(date) {
	var n = date.getFullYear(); 
	var y = date.getMonth() + 1;
	var r = date.getDate(); 
	var mytime = date.toLocaleTimeString(); 
	var mytimes = n+ "-" + y + "-" + r + " " + mytime;
  return mytimes;
}