dcsimg
Date Comparison for getting the mail for a particular date specified. the date formats change for every mail. how do i compare the date
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   snehal_gandhi
Posted On:   Saturday, August 24, 2002 01:04 AM

hi i'm developing an email application. in that i read all the mails from the mail server. in my application when a request comes for reading a mail for a specified date (getting from the user in the format of eg: 23-07-2002), how do i get the mail from the mail server which has different date formats. now for example when i send a mail from yahoo to hotmail, the date is of different format, and when i compare that it's not correctly checking with the date that the user has specified. how do i compare the dates in this case. can i get the code for this. regards Snehal    More>>

hi


i'm developing an email application. in that i read all the mails from the mail server.
in my application when a request comes for reading a mail for a specified date (getting from the user in the format of eg: 23-07-2002),
how do i get the mail from the mail server which has different date formats. now for example when i send a mail
from yahoo to hotmail, the date is of different format, and when i compare that it's not correctly checking with the
date that the user has specified.
how do i compare the dates in this case. can i get the code for this.


regards


Snehal

   <<Less

Re: Date Comparison for getting the mail for a particular date specified. the date formats change for every mail. how do i compare the date

Posted By:   Holger_Kyas  
Posted On:   Wednesday, September 18, 2002 12:39 AM

Hi Snehal,
here is a helpful Example by Sun I found:


/*
* Copyright (c) 1995-1998 Sun Microsystems, Inc. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*/

import java.util.*;
import java.text.*;

public class DateFormatDemo {

static public void displayDate(Locale currentLocale) {

Date today;
String dateOut;
DateFormat dateFormatter;

dateFormatter =
DateFormat.getDateInstance(DateFormat.DEFAULT, currentLocale);
today = new Date();
dateOut = dateFormatter.format(today);

System.out.println(dateOut + " " + currentLocale.toString());
}

static public void showBothStyles(Locale currentLocale) {

Date today;
String result;
DateFormat formatter;

int[] styles = {
DateFormat.DEFAULT,
DateFormat.SHORT,
DateFormat.MEDIUM,
DateFormat.LONG,
DateFormat.FULL
};

System.out.println();
System.out.println("Locale: " + currentLocale.toString());
System.out.println();

today = new Date();

for (int k = 0; k < styles.length; k++) {
formatter = DateFormat.getDateTimeInstance(
styles[k], styles[k], currentLocale);
result = formatter.format(today);
System.out.println(result);
}
}

static public void showDateStyles(Locale currentLocale) {

Date today = new Date();
String result;
DateFormat formatter;

int[] styles = {
DateFormat.DEFAULT,
DateFormat.SHORT,
DateFormat.MEDIUM,
DateFormat.LONG,
DateFormat.FULL
};

System.out.println();
System.out.println("Locale: " + currentLocale.toString());
System.out.println();

for (int k = 0; k < styles.length; k++) {
formatter =
DateFormat.getDateInstance(styles[k], currentLocale);
result = formatter.format(today);
System.out.println(result);
}
}

static public void showTimeStyles(Locale currentLocale) {

Date today = new Date();
String result;
DateFormat formatter;

int[] styles = {
DateFormat.DEFAULT,
DateFormat.SHORT,
DateFormat.MEDIUM,
DateFormat.LONG,
DateFormat.FULL
};

System.out.println();
System.out.println("Locale: " + currentLocale.toString());
System.out.println();

for (int k = 0; k < styles.length; k++) {
formatter =
DateFormat.getTimeInstance(styles[k], currentLocale);
result = formatter.format(today);
System.out.println(result);
}
}

static public void main(String[] args) {

Locale[] locales = {
new Locale("fr","FR"),
new Locale("de","DE"),
new Locale("en","US")
};

for (int i = 0; i < locales.length; i++) {
displayDate(locales[i]);
}

showDateStyles(new Locale("en","US"));
showDateStyles(new Locale("fr","FR"));

showTimeStyles(new Locale("en","US"));
showTimeStyles(new Locale("de","DE"));

showBothStyles(new Locale("en","US"));
showBothStyles(new Locale("fr","FR"));

}
}

Re: Date Comparison for getting the mail for a particular date specified. the date formats change for every mail. how do i compare the date

Posted By:   suraj_berwal  
Posted On:   Sunday, September 15, 2002 09:34 PM

dear snehal,
try using DateFormat class found in java.text.* package to convert the dates in the desired format. this package is part of the SDK.
regards,
Suraj Berwal.
About | Sitemap | Contact