Java Utililty Methods Date Convert

List of utility methods to do Date Convert

Description

The list of methods to do Date Convert are organized into topic(s).

Method

longdateToLong(final Date date)
date To Long
final Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.getTimeInMillis();
StringDateToMask(Date javaDateType)
Date To Mask
Calendar dt = Calendar.getInstance();
dt.setTime(javaDateType);
String dia = String.valueOf(dt.get(Calendar.DAY_OF_MONTH));
String mes = String.valueOf(dt.get(Calendar.MONTH) + 1);
String ano = String.valueOf(dt.get(Calendar.YEAR));
while (dia.length() < 2) {
    dia = "0".concat(dia);
while (mes.length() < 2) {
    mes = "0".concat(mes);
while (ano.length() < 4) {
    ano = "0".concat(ano);
return dia.concat("/").concat(mes).concat("/").concat(ano);
DatedateToMorining(Date date)
date To Morining
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
return calendar.getTime();
LongdateToNumber(Date date)
date To Number
if (date == null) {
    return null;
Calendar c = Calendar.getInstance();
c.setTime(date);
String month;
String day;
if ((c.get(Calendar.MONTH) + 1) >= 10) {
...
longdateToQTime(final Date date)
Converts a Date object to a 32-bit value that be used in the file format.
final Calendar c = Calendar.getInstance();
c.clear();
c.setTime(date);
if (c.getTimeZone().inDaylightTime(c.getTime())) {
    c.add(Calendar.HOUR_OF_DAY, 1);
final long seconds = c.getTimeInMillis() / 1000;
long result;
...
StringdateToRRNDate(Date date)
date To RRN Date
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
StringBuilder builder = new StringBuilder();
builder.append(calendar.get(Calendar.DAY_OF_MONTH));
builder.append(' ');
builder.append(RRNMonthNames[calendar.get(Calendar.MONTH)]);
builder.append(' ');
builder.append(calendar.get(Calendar.YEAR));
...
StringDateToStr(java.util.Date val)
This converts a java.util.Date to a date string in the form of YYYY-MM-DD.
Calendar cal = Calendar.getInstance();
StringBuffer sb = new StringBuffer();
String year, month, day;
if (val != null) {
    cal.setTime(val);
year = "" + cal.get(Calendar.YEAR);
month = "" + (cal.get(Calendar.MONTH) + 1);
...
StringdateToString(Date date)
Pretvara datum u tekst, i to samo dan (format "yyyy-MM-dd").
if (date == null)
    return "";
StringBuilder sb = new StringBuilder(10);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH) - Calendar.JANUARY + 1;
int year = cal.get(Calendar.YEAR);
...
StringdateToString(Date date)
date To String
int y, m, d;
Calendar c = Calendar.getInstance();
String dateString = null;
c.setTime(date);
y = c.get(Calendar.YEAR);
m = c.get(Calendar.MONTH) + 1;
d = c.get(Calendar.DATE);
dateString = (y < 10 ? "0" : "") + y + "-" + (m < 10 ? "0" : "") + m + "-" + (d < 10 ? "0" : "") + d;
...
StringdateToString(Date date)
Method dateToString.
Calendar expireCa = new GregorianCalendar();
expireCa.setTime(date);
int year = expireCa.get(Calendar.YEAR);
int month = expireCa.get(Calendar.MONTH);
int day = expireCa.get(Calendar.DAY_OF_MONTH);
StringBuffer sb = new StringBuffer();
sb.append(year);
month++;
...