Nurettin Arslankaya wrote:
Thanks for showing us code, this is much more informative:
public static Date MStrToDate(String Dt) throws ParseException {
Date trh;
String dts = Dt.trim();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss");
SimpleTimeZone tz=new SimpleTimeZone(0,"TURKEY/ANKARA");
The first problem is that this is NOT a known Java timezone, but
is code which constructs an arbitrqary timezone with the name you provided.
This results in a 0:00 offset timezone.
For curious reasons mostly to do with fact there is NOT
any international convention for the name of timezones, your
choices are probably:
Europe/Istanbul
Asia/Istanbul
Both of the above are the same GMT offset and DLS (Daylight savings) change date.
see also TimeZone.getAvailableIDs()
see
http://bepp.8m.com/english/java_applets/time_zone_java_applet.htm
then use TimeZone.getTimeZone( "Asia/Istanbul" );
Try this code:
SimpleTimeZone tz=new SimpleTimeZone(0,"TURKEY/ANKARA");
System.out.println( "Tz savings: " + tz.getDSTSavings() );
System.out.println( "Tz name: " + tz.getDisplayName() );
TimeZone tz2 = TimeZone.getTimeZone("Asia/Istanbul");
System.out.println( "Tz savings: " + tz2.getDSTSavings() );
System.out.println( "Tz name: " + tz2.getDisplayName() );
SimpleTimeZone tz3 = new SimpleTimeZone(0,"Africa/Kingdom of Prestor John");
System.out.println( tz.hasSameRules(tz3) );
Notice that an imaginary entry for "The Kingdom of Prestor John"
results in a TZ the same as the one you created.
What you have said here is that you DO NOT want to apply the DLS for many years
to come. Why?
formatter.setTimeZone(tz);
tz.setDefault(tz);
This sets the default timezone for all places where a timezone
is not specified but when one is needed.
It is really TimeZone.setDefault(tz), a static call.
I doubt you want do that, since this will effect all
future Calendars and TimeZones and SimpleDateFormats you create.
formatter.setTimeZone(TimeZone.getDefault());
Formatter.setTimeZone( tz ) would have been as good.
if (!dts.equals(formatter.format(trh))){
throw new ParseException(dts + " geçerli bir tarih değil.
",0);
My Turkish ain't so good, would you mind putting that in English next time?
/*
the code above is throws exception because, the input text and
formatted text are different. "February 31" is parsed without any
error. But in other programming languages this text can throw error.
If you want everthing to take only valid dates, set the calendar
in the SimpleDateFormat to strict
You can do this with
formatter.getCalendar().setLenient( false );
Maybe this was your original problem which you needed to solve.
I hope so.
So I need to recheck formatted text aganist to wrong data. But this
test fails at daylight saving starts days.
Start days only? I think you have many more dates on which the
problem occurs.
The code above is running
correct. Possibly startyear may not needed. this code is working
several places and operating systems (especially Windows based) we
distribute Java runtime 1.4 that I am using. The error occured two
times in previous. One at April, 1, 1980 and the other at April, 14,
1975.
thanks for your interests.
I'm still interested. Let me know how it turns out.
-Paul