/*** @author Uki D. Lucas* June 19, 2007 - Created.*/package com.ucc.csd.server.common;import java.text.DateFormat;import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar;import java.util.Locale;public class DateHelper{public static final int MILISECONDS_IN_ONE_HOUR = 3600000;public static Date build(int year, int month, int day){GregorianCalendar calendar = new GregorianCalendar();calendar.set(year, month - 1, day);return calendar.getTime();}public static boolean compareDates(Date startDt, Date endDate){if (endDate.after(startDt))return true;return false;}public static Date incrementDays(Date date, int days){GregorianCalendar calendar = new GregorianCalendar();calendar.setTime(date);int year = calendar.get(Calendar.YEAR);int month = calendar.get(Calendar.MONTH) + 1;int day = calendar.get(Calendar.DAY_OF_MONTH) + days;System.out.println("year: " + year);System.out.println("month: " + month);System.out.println("day: " + day);return DateHelper.build(year, month, day);}public static String convertToLocalized(Date date, String countryCode, String languageCode, int format){Locale locale = new Locale(languageCode, countryCode);DateFormat df = DateFormat.getDateInstance(format, locale);return df.format(date);}/*** returns string eg. 27-Jul-2006** @author Uki D. Lucas*/public static String convertToOracle(Date date){java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MMM-yyyy");return sdf.format(date);}/** outputs format: 5/14/08 */public static String convertToShortLocalizedUSA(Date date){String countryCode = "US";String languageCode = "en";int format = DateFormat.SHORT;return convertToLocalized(date, countryCode, languageCode, format);}/*** returns string eg. 20070321** @author Uki D. Lucas*/public static String convertToyyyyMMdd(Date date){java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd");return sdf.format(date);}/*** returns string eg. 2007* @author Uki D. Lucas*/public static String getJulian(Date date){java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("DDD");return sdf.format(date);}/*** returns string eg. 2007* @author Uki D. Lucas*/public static String getYear(Date date){java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");return sdf.format(date);}}
Java Date() Helper
find similar posts:
Java
My favorite quotations..
“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.” by Robert A. Heinlein
"We are but habits and memories we chose to carry along." ~ Uki D. Lucas
Recommended pages
Popular Recent Articles
-
I have noticed a very unsettling statistic on my blog. This prompted a fascinating question about AI, blogs' future, and maybe even the...
-
I live in a very rugged Pacific Northwest (PNW). The terrain consists of sharp rocks in summer and wet or snow-covered sharp rocks in winte...
-
In this post, I reflect on the profound impact of habits and effective time management over a year. I share personal experiences and stra...
-
All images and videos were taken by Uki, the author. At this point, I could only export raw movie footage from today's dive. In the fut...
-
After four meetings in a row, I had the need to get out of the office and go to Redmond French Cafe . The “Croque Madame” plate is not the b...
-
You know when you live in the right town when, on a single walk, you have to cross under a fallen tree and chase a coyote out of your path. ...
-
See the photo below. When I was posting my previous article on X.co (Twitter) I was literally following a post of Elon Musk. I thought it wa...
-
I have been wearing wool products for a very long time now. The highlanders of the region where I was born were wearing wool in winter and ...
-
Only 9 years ago - 500,000 downloads - 2303 reviews Not too shabby. Today - couldn't log in Please SUBSCRIBE: https://ukidlucas.beehiiv...
-
This slingshot shot took a lot of practice , but she had fun and became very consistent . Buy it on Amazon: Item Name Author Producer Amaz...