下面列出了java.text.SimpleDateFormat#applyPattern ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void t_formatToCharacterIterator() {
TimeZone tz = TimeZone.getTimeZone("EST");
Calendar cal = new GregorianCalendar(tz);
cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01);
cal.set(Calendar.MILLISECOND, 0);
Date date = cal.getTime();
SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US);
format.setTimeZone(tz);
format.applyPattern("yyyyMMddHHmmss");
t_Format(1, date, format, getDateVector1());
format.applyPattern("w W dd MMMM yyyy EEEE");
t_Format(2, date, format, getDateVector2());
format.applyPattern("h:m z");
t_Format(3, date, format, getDateVector3());
format.applyPattern("h:m Z");
t_Format(5, date, format, getDateVector5());
// with all pattern chars, and multiple occurences
format.applyPattern("G GGGG y yy yyyy M MM MMM MMMM d dd ddd k kk kkk H HH HHH h hh hhh m mmm s ss sss S SS SSS EE EEEE D DD DDD F FF w www W WWW a aaa K KKK z zzzz Z ZZZZ");
t_Format(4, date, format, getDateVector4());
}
/**
* 根据给出的Date值和格式串采用操作系统的默认所在的国家风格来格式化时间,并返回相应的字符串
*
* @param date
* 日期对象
* @param formatStr
* 日期格式
* @return 如果为null,返回字符串""
*/
public static String formatDateTimetoString(Date date, String formatStr) {
String reStr = "";
if (date == null || formatStr == null || formatStr.trim().length() < 1) {
return reStr;
}
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern(formatStr);
reStr = sdf.format(date);
return reStr == null ? "" : reStr;
}
@Test
public void testStuff() {
CalendarDate cd = CalendarDate.present();
/*
* {"S", "M", "L", "F", "-"}
* System.out.printf("%s%n", DateTimeFormat.forStyle("SS").print(cd.getDateTime()));
* System.out.printf("%s%n", DateTimeFormat.forStyle("MM").print(cd.getDateTime()));
* System.out.printf("%s%n", DateTimeFormat.forStyle("LL").print(cd.getDateTime()));
* System.out.printf("%s%n", DateTimeFormat.forStyle("FF").print(cd.getDateTime()));
*/
System.out.printf("%s%n", cd);
System.out.printf("toDateTimeStringISO=%s%n", toDateTimeStringISO(cd));
System.out.printf(" toDateTimeString=%s%n", toDateTimeString(cd));
System.out.printf(" toDateString=%s%n", toDateString(cd));
System.out.printf(" toTimeUnits=%s%n", toTimeUnits(cd));
System.out.printf("===============================%n");
Date d = cd.toDate();
System.out.printf("cd.toDate()=%s%n", toDateTimeString(d));
SimpleDateFormat udunitDF = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);
udunitDF.setTimeZone(TimeZone.getTimeZone("UTC"));
udunitDF.applyPattern("yyyy-MM-dd HH:mm:ss.SSS 'UTC'");
System.out.printf(" udunitDF=%s%n", udunitDF.format(d));
System.out.printf("===============================%n");
DateFormatter df = new DateFormatter();
System.out.printf(" toTimeUnits(date)=%s%n", toTimeUnits(cd));
System.out.printf("toDateTimeString(date)=%s%n", df.toDateTimeString(d));
System.out.printf("toDateOnlyString(date)=%s%n", df.toDateOnlyString(d));
}
/**
* 按照参数提供的格式将Date类型时间转换为字符串
* @param date
* @param formaterString
* @return
*/
public static String toString(Date date, String formaterString) {
String time;
SimpleDateFormat formater = new SimpleDateFormat();
formater.applyPattern(formaterString);
time = formater.format(date);
return time;
}
@Test
public void Timestampからのconvertテスト() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyy/MM/dd HH:mm:ss.SSS");
String ymdhmss = "2011/11/11 13:45:56.789";
Date d = sdf.parse(ymdhmss);
Timestamp ts = new Timestamp(d.getTime());
assertEquals("2011/11/11 13:45:56", new StringConverter().convert(ts));
}
private void assertFormat(SimpleDateFormat format, String pattern, Calendar cal,
String expected, int field) {
StringBuffer buffer = new StringBuffer();
FieldPosition position = new FieldPosition(field);
format.applyPattern(pattern);
format.format(cal.getTime(), buffer, position);
String result = buffer.toString();
assertTrue("Wrong format: \"" + pattern + "\" expected: " + expected + " result: " + result,
result.equals(expected));
assertEquals("Wrong begin position: " + pattern + "\n" + "expected: " + expected + "\n" +
"field: " + field, 1, position.getBeginIndex());
assertTrue("Wrong end position: " + pattern + " expected: " + expected + " field: " + field,
position.getEndIndex() == result.length());
}
/**
* Returns date before given days
*
* @param days days to before
* @return string date string before days
*/
public static String getDateBefore(int days) {
Date today = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(today);
cal.add(Calendar.DAY_OF_MONTH, days * -1);
Date date = cal.getTime();
SimpleDateFormat gmtFormat = new SimpleDateFormat();
gmtFormat.applyPattern("yyyy-MM-dd 00:00:00");
TimeZone gmtTime = TimeZone.getTimeZone("GMT");
gmtFormat.setTimeZone(gmtTime);
return gmtFormat.format(date);
}
/**
* <p>Appends the date, time and/or datetime to the given filename (before the extension if it exists), using the
* provided patterns.</p>
*
* @param filename the original filename (can have path and variables)
* @param addDate if the date is to be added
* @param datePattern the pattern to be used for the date
* @param addTime if the time is to be added
* @param timePattern the pattern to be used for the time
* @param specifyFormat if the datetime is to be added
* @param datetimeFormat the pattern to be used for the datetime
* @return the resulting filename after adding the specified suffixes to the given filename
*/
protected String addDatetimeToFilename( String filename, boolean addDate, String datePattern, boolean addTime,
String timePattern, boolean specifyFormat, String datetimeFormat ) {
if ( Utils.isEmpty( filename ) ) {
return null;
}
// Replace possible environment variables...
String realfilename = environmentSubstitute( filename );
String filenameNoExtension = FilenameUtils.removeExtension( realfilename );
String extension = FilenameUtils.getExtension( realfilename );
// If an extension exists, add the corresponding dot before
if ( !StringUtil.isEmpty( extension ) ) {
extension = '.' + extension;
}
final SimpleDateFormat sdf = new SimpleDateFormat();
Date now = new Date();
if ( specifyFormat && !Utils.isEmpty( datetimeFormat ) ) {
sdf.applyPattern( datetimeFormat );
String dt = sdf.format( now );
filenameNoExtension += dt;
} else {
if ( addDate && null != datePattern ) {
sdf.applyPattern( datePattern );
String d = sdf.format( now );
filenameNoExtension += '_' + d;
}
if ( addTime && null != timePattern ) {
sdf.applyPattern( timePattern );
String t = sdf.format( now );
filenameNoExtension += '_' + t;
}
}
return filenameNoExtension + extension;
}
public static String calculateByDate(String date,String format, int dayOffset) {
SimpleDateFormat formater = new SimpleDateFormat();
try {
formater.applyPattern(format);
Date time = formater.parse(date);
long ts = time.getTime()+dayOffset*24*3600*1000L;
Date newDate = new Date(ts);
return date2String(format,newDate);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}
public static String getDateString(final Context context, final long time, final boolean hasYear, final boolean hasWeek) {
final Date date = new Date(time);
final SimpleDateFormat formatter = getFormatter();
if (hasYear && hasWeek) {
formatter.applyPattern(context.getString(R.string.date_format_week_year));
} else if (hasYear) {
formatter.applyPattern(context.getString(R.string.date_format_year));
} else if (hasWeek) {
formatter.applyPattern(context.getString(R.string.date_format_week));
} else {
formatter.applyPattern(context.getString(R.string.date_format_default));
}
return formatter.format(date);
}
@Override
protected Object parse(Object value, String pattern) throws ParseException
{
SimpleDateFormat formatter = getFormatter(pattern, locale);
if (pattern != null)
{
if (locPattern) {
formatter.applyLocalizedPattern(pattern);
}
else {
formatter.applyPattern(pattern);
}
}
return formatter.parse((String) value);
}
private void writeDate(Date date) throws Exception
{
// sample 19990625152315 (7 octets) represents date "1999-06-25 15:23:15"
// sample 20990603 (4 octets) represents date "2099-06-30 00:00:00"
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyyMMddHHmmss");
String dateData = sdf.format(date);
// scan from the last octet to start and remove all trailing 00s
for (int i = 6; i >= 0; i--)
{
if (dateData.endsWith("00"))
{
dateData = dateData.substring(0, i * 2);
}
else
{
break;
}
}
// generate the byte[] from remaining date data
byte[] dataBytes = PduUtils.pduToBytes(dateData);
// mark opaque data
this.baos.write(WapPushUtils.WBXML_OPAQUE_DATA);
// write octet length
this.baos.write(dataBytes.length);
// write data
this.baos.write(dataBytes);
}
public static String getCurrentDateTime(String pattern) {
GregorianCalendar currentCalendar = new GregorianCalendar();
SimpleDateFormat simpleDateFormat = (SimpleDateFormat)SimpleDateFormat.getDateTimeInstance();
simpleDateFormat.applyPattern(pattern);
return simpleDateFormat.format(currentCalendar.getTime());
}
/**
* Update Assignment. This method is not currently called by Assignments 1.
*/
public void updateAssignment(String siteId, String taskId) throws SubmissionException {
log.info("updateAssignment(" + siteId + " , " + taskId + ")");
// get the assignment reference
String taskTitle = getAssignmentTitle(taskId);
log.debug("Creating assignment for site: " + siteId + ", task: " + taskId + " tasktitle: " + taskTitle);
SimpleDateFormat dform = ((SimpleDateFormat) DateFormat.getDateInstance());
dform.applyPattern(TURNITIN_DATETIME_FORMAT);
Calendar cal = Calendar.getInstance();
// set this to yesterday so we avoid timezpne problems etc
cal.add(Calendar.DAY_OF_MONTH, -1);
String dtstart = dform.format(cal.getTime());
// set the due dates for the assignments to be in 5 month's time
// turnitin automatically sets each class end date to 6 months after it
// is created
// the assignment end date must be on or before the class end date
// TODO use the 'secret' function to change this to longer
cal.add(Calendar.MONTH, 5);
String dtdue = dform.format(cal.getTime());
String fcmd = "3"; // new assignment
String fid = "4"; // function id
String utp = "2"; // user type 2 = instructor
String s_view_report = "1";
// erater
String erater = "0";
String ets_handbook = "1";
String ets_dictionary = "en";
String ets_spelling = "1";
String ets_style = "1";
String ets_grammar = "1";
String ets_mechanics = "1";
String ets_usage = "1";
String cid = siteId;
String assignid = taskId;
String assign = taskTitle;
String ctl = siteId;
String assignEnc = assign;
try {
if (assign.contains("&")) {
// log.debug("replacing & in assingment title");
assign = assign.replace('&', 'n');
}
assignEnc = assign;
log.debug("Assign title is " + assignEnc);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Map params = TurnitinAPIUtil.packMap(turnitinConn.getBaseTIIOptions(), "assign", assignEnc, "assignid",
assignid, "cid", cid, "ctl", ctl, "dtdue", dtdue, "dtstart", dtstart, "fcmd", fcmd, "fid", fid,
"s_view_report", s_view_report, "utp", utp, "erater", erater, "ets_handbook", ets_handbook,
"ets_dictionary", ets_dictionary, "ets_spelling", ets_spelling, "ets_style", ets_style, "ets_grammar",
ets_grammar, "ets_mechanics", ets_mechanics, "ets_usage", ets_usage);
params.putAll(getInstructorInfo(siteId));
Document document = null;
try {
document = turnitinConn.callTurnitinReturnDocument(params);
} catch (TransientSubmissionException tse) {
log.error("Error on API call in updateAssignment siteid: " + siteId + " taskid: " + taskId, tse);
return;
} catch (SubmissionException se) {
log.error("Error on API call in updateAssignment siteid: " + siteId + " taskid: " + taskId, se);
return;
}
Element root = document.getDocumentElement();
int rcode = new Integer(
((CharacterData) (root.getElementsByTagName("rcode").item(0).getFirstChild())).getData().trim())
.intValue();
if ((rcode > 0 && rcode < 100) || rcode == 419) {
log.debug("Create Assignment successful");
} else {
log.debug("Assignment creation failed with message: "
+ ((CharacterData) (root.getElementsByTagName("rmessage").item(0).getFirstChild())).getData().trim()
+ ". Code: " + rcode);
throw new SubmissionException(
getFormattedMessage("assignment.creation.error.with.code",
((CharacterData) (root.getElementsByTagName("rmessage").item(0).getFirstChild())).getData().trim(),
rcode));
}
}
public void notifySiteCreation(Site site, List notifySites, boolean courseSite, String termTitle, String requestEmail, boolean sendToRequestEmail, boolean sendToUser) {
User currentUser = userDirectoryService.getCurrentUser();
String currentUserDisplayName = currentUser!=null?currentUser.getDisplayName():"";
String currentUserDisplayId = currentUser!=null?currentUser.getDisplayId():"";
String currentUserEmail = currentUser!=null?currentUser.getEmail():"";
SimpleDateFormat dform = ((SimpleDateFormat) DateFormat.getDateInstance());
dform.applyPattern("yyyy-MM-dd HH:mm:ss");
String dateDisplay = dform.format(new Date());
String from = currentUserEmail;
String to = requestEmail;
String headerTo = requestEmail;
String replyTo = currentUserEmail;
Map<String, String> replacementValues = new HashMap<>();
replacementValues.put("currentUserDisplayName", currentUserDisplayName);
replacementValues.put("currentUserDisplayId", currentUserDisplayId);
replacementValues.put("currentUserEmail", currentUserEmail);
replacementValues.put("dateDisplay", dateDisplay);
replacementValues.put("termTitle", termTitle);
replacementValues.put("serviceName", serverConfigurationService.getString( "ui.service", serverConfigurationService.getServerName() ) );
replacementValues.put("siteTitle", site!=null?site.getTitle():"");
replacementValues.put("siteId", site!=null?site.getId():"");
replacementValues.put("courseSite", String.valueOf(courseSite));
StringBuilder buf = new StringBuilder();
if (notifySites!= null)
{
int nbr_sections = notifySites.size();
replacementValues.put("numSections", String.valueOf(nbr_sections));
for (int i = 0; i < nbr_sections; i++) {
String course = (String) notifySites.get(i);
buf.append( course ).append("\n");
}
}
else
{
replacementValues.put("numSections", "0");
}
replacementValues.put("sections", buf.toString());
if (sendToRequestEmail)
{
emailTemplateServiceSend(NOTIFY_SITE_CREATION, (new ResourceLoader()).getLocale(), currentUser, from, to, headerTo, replyTo, replacementValues);
}
if (sendToUser)
{
// send a confirmation email to site creator
from = requestEmail;
to = currentUserEmail;
headerTo = currentUserEmail;
replyTo = serverConfigurationService.getString("setup.request","[email protected]" + serverConfigurationService.getServerName());
emailTemplateServiceSend(NOTIFY_SITE_CREATION_CONFIRMATION, (new ResourceLoader()).getLocale(), currentUser, from, to, headerTo, replyTo, replacementValues);
}
}
/**
* {@inheritDoc}
*/
public String notifyCourseRequestSupport(String requestEmail, String serverName, String request, String termTitle, int requestListSize, String requestSectionInfo,
String officialAccountName, String siteTitle, String siteId, String additionalInfo, boolean requireAuthorizer, String authorizerNotified, String authorizerNotNotified)
{
ResourceLoader rb = new ResourceLoader("UserNotificationProvider");
User currentUser = userDirectoryService.getCurrentUser();
String currentUserDisplayName = currentUser!=null?currentUser.getDisplayName():"";
String currentUserDisplayId = currentUser!=null?currentUser.getDisplayId():"";
String currentUserEmail = currentUser!=null?currentUser.getEmail():"";
// To Support
String from = currentUserEmail;
String to = requestEmail;
String headerTo = requestEmail;
String replyTo = currentUserEmail;
StringBuffer buf = new StringBuffer();
buf.append(rb.getString("java.to") + "\t\t" + serverName
+ " " + rb.getString("java.supp") + "\n");
buf.append("\n" + rb.getString("java.from") + "\t"
+ currentUserDisplayName + "\n");
if ("new".equals(request)) {
buf.append(rb.getString("java.subj") + "\t"
+ rb.getString("java.sitereq") + "\n");
} else {
buf.append(rb.getString("java.subj") + "\t"
+ rb.getString("java.sitechreq") + "\n");
}
SimpleDateFormat dform = ((SimpleDateFormat) DateFormat.getDateInstance());
dform.applyPattern("yyyy-MM-dd HH:mm:ss");
String dateDisplay = dform.format(new Date());
buf.append(rb.getString("java.date") + "\t" + dateDisplay + "\n\n");
if ("new".equals(request)) {
buf.append(rb.getString("java.approval") + " "
+ serverName + " "
+ rb.getString("java.coursesite") + " ");
} else {
buf.append(rb.getString("java.approval2") + " "
+ serverName + " "
+ rb.getString("java.coursesite") + " ");
}
if (!termTitle.isEmpty()) {
buf.append(termTitle);
}
if (requestListSize > 1) {
buf.append(" " + rb.getString("java.forthese") + " "
+ requestListSize + " " + rb.getString("java.sections")
+ "\n\n");
} else {
buf.append(" " + rb.getString("java.forthis") + "\n\n");
}
// the course section information
buf.append(requestSectionInfo);
buf.append(rb.getString("java.name") + "\t" + currentUserDisplayName
+ " (" + officialAccountName + " " + currentUserDisplayId
+ ")\n");
buf.append(rb.getString("java.email") + "\t" + replyTo + "\n");
buf.append(rb.getString("java.sitetitle") + "\t" + siteTitle + "\n");
buf.append(rb.getString("java.siteid") + "\t" + siteId + "\n\n");
buf.append(rb.getString("java.siteinstr") + "\n" + additionalInfo
+ "\n\n");
if (requireAuthorizer)
{
// if authorizer is required
if (!authorizerNotified.isEmpty()) {
buf.append(rb.getString("java.authoriz") + " " + authorizerNotified + " " + rb.getString("java.asreq"));
}
if (!authorizerNotNotified.isEmpty()){
buf.append(rb.getString("java.thesiteemail") + " " + authorizerNotNotified + " " + rb.getString("java.asreq"));
}
}
String content = buf.toString();
// message subject
String message_subject = rb.getString("java.sitereqfrom") + " " + currentUserDisplayName + " " + rb.getString("java.for") + " " + termTitle;
try
{
emailService.send(from, to, message_subject, content, headerTo, replyTo, null);
return content;
}
catch (Exception e)
{
log.warn(this + " problem in send site request email to support for " + currentUserDisplayName );
return "";
}
}
@Override
@Transactional
@Validate("sendMailing")
public MaildropEntry addMaildropEntry(MailingModel model, List<UserAction> userActions) throws Exception {
if (!DateUtil.isValidSendDate(model.getSendDate())) {
throw new SendDateNotInFutureException();
}
Calendar now = Calendar.getInstance();
Mailing mailing = getMailing(model);
if (model.getMaildropStatus() == MaildropStatus.WORLD && maildropService.isActiveMailing(mailing.getId(), mailing.getCompanyID())) {
throw new WorldMailingAlreadySentException();
}
MaildropEntry maildrop = new MaildropEntryImpl();
maildrop.setStatus(model.getMaildropStatus().getCode());
maildrop.setMailingID(model.getMailingId());
maildrop.setCompanyID(model.getCompanyId());
maildrop.setStepping(model.getStepping());
maildrop.setBlocksize(model.getBlocksize());
maildrop.setSendDate(model.getSendDate());
Calendar tmpGen = Calendar.getInstance();
tmpGen.setTime(model.getSendDate());
tmpGen.add(Calendar.MINUTE, -this.getMailGenerationMinutes(model.getCompanyId()));
if(tmpGen.before(now)) {
tmpGen=now;
}
maildrop.setGenDate(tmpGen.getTime());
maildrop.setGenChangeDate(now.getTime());
if( model.getMaildropStatus() == MaildropStatus.WORLD) {
maildrop.setGenStatus(DateUtil.isDateForImmediateGeneration(maildrop.getGenDate()) ? 1 : 0);
} else if( model.getMaildropStatus() == MaildropStatus.TEST || model.getMaildropStatus() == MaildropStatus.ADMIN) {
maildrop.setGenStatus( 1);
}
mailing.getMaildropStatus().add(maildrop);
mailingDao.saveMailing(mailing, false);
if (logger.isInfoEnabled()) {
logger.info("send mailing id: " + mailing.getId() + " type: "+maildrop.getStatus());
}
SimpleDateFormat dateTimeFormat = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.UK);
dateTimeFormat.applyPattern(dateTimeFormat.toPattern().replaceFirst("y+", "yyyy").replaceFirst(", ", " "));
String strDate = dateTimeFormat.format(model.getSendDate());
String description = String.format("Date: %s. Mailing %s(%d) %s", strDate, mailing.getShortname(), mailing.getId(), "normal");
userActions.add(new UserAction("edit send date", description));
return maildrop;
}
static DateFormat getMediumNoYear(Locale locale) {
SimpleDateFormat format = (SimpleDateFormat) getMediumFormat(locale);
format.applyPattern(removeYearFromDateFormatPattern(format.toPattern()));
return format;
}
private String getWeek(final SimpleDateFormat sdf, final Date date, final int mysqlWeekMode) {
sdf.applyPattern("w");
return sdf.format(date);
}
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
* @throws CerberusException
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, CerberusException {
String charset = request.getCharacterEncoding() == null ? "UTF-8" : request.getCharacterEncoding();
String application = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("application"), "", charset);
String object = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("object"), "", charset);
int width = (!StringUtils.isEmpty(request.getParameter("w"))) ? Integer.valueOf(request.getParameter("w")) : -1;
int height = (!StringUtils.isEmpty(request.getParameter("h"))) ? Integer.valueOf(request.getParameter("h")) : -1;
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IApplicationObjectService applicationObjectService = appContext.getBean(IApplicationObjectService.class);
BufferedImage image = applicationObjectService.readImageByKey(application, object);
BufferedImage b;
if (image != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
/**
* If width and height not defined, get image in real size
*/
if (width == -1 && height == -1) {
b = image;
} else {
ResampleOp rop = new ResampleOp(DimensionConstrain.createMaxDimension(width, height, true));
rop.setNumberOfThreads(4);
b = rop.filter(image, null);
}
ImageIO.write(b, "png", baos);
// byte[] bytesOut = baos.toByteArray();
} else {
// create a buffered image
ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);
b = ImageIO.read(bis);
bis.close();
}
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.setTimeZone(new SimpleTimeZone(0, "GMT"));
sdf.applyPattern("dd MMM yyyy HH:mm:ss z");
response.setHeader("Last-Modified", sdf.format(DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360)));
response.setHeader("Expires", sdf.format(DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360)));
ImageIO.write(b, "png", response.getOutputStream());
}