ورود

View Full Version : اشکال کد در تقویم شمسی



mojtaba_java
یک شنبه 11 فروردین 1387, 18:27 عصر
با سلام خدمت اساتید ارجمند
عید همه مبارک
من می خواهم تاریخ شمسی را در یک textbox نشان دهم اگر ممکن است مشکلات کد زیر را بگویید.
یا اگر کد بهتری برای تبدیل سراغ دارید بگویید.
با تشکر





import java.util.*;
import java.text.*;
import java.util.Date;
public class Tarekh {
static public String Tarekh() {
String dayName[]={ "sh","1k","2s","3s","4s","5s","jome"} ;
int monName[] = { 10,11,12,1,2,3,4,5,6,7,8,9};
int mm,mr,ii;
String rr;
Date now = new Date();
rr=dayName[now.getDate()];
if (now.getMonth() <= 1 )
{
ii=now.getYear()-622;
} else {
if ( now.getDate() <= 21 && now.getMonth() == 2)
{ ii=now.getYear()-622;
} else {
ii=now.getYear()-621;
}
}
if ( now.getMonth() == 6 || now.getMonth() == 7 || now.getMonth() == 8 || now.getMonth() == 9)
{
if ( now.getDate() <=22 )
{
mm=monName[now.getMonth()] ;
} else {mm=monName[now.getMonth()+1];
}
}
if ( now.getMonth() == 4 || now.getMonth() == 5 || now.getMonth() == 10 )
{
if ( now.getDate() <=21 ) { mm=monName[now.getMonth()] ;
} else {mm=monName[now.getMonth()+1];
}
}
if ( now.getMonth() == 0 || now.getMonth() == 2 || now.getMonth() == 3 )
{
if ( now.getDate() <=20 ) { mm=monName[now.getMonth()];
} else { mm=monName[now.getMonth()+1];
}
}
if ( now.getMonth() == 1) { if ( now.getDate() <=19 )
{
mm=monName[now.getMonth()] ;
} else { mm=monName[now.getMonth()+1];
}
}
if ( now.getMonth() == 11) { if ( now.getDate() <=21 )
{
mm=monName[now.getMonth()];
} else { mm=monName[now.getMonth()-11] ;
}
}
if ( now.getMonth() == 2 || now.getMonth() == 3 || now.getMonth() == 0 )
{
if ( now.getDate() <=20 ) {mr=now.getDate()+10;
} else { mr=now.getDate()+10-30 ;
}
}
if ( now.getMonth() == 4 || now.getMonth() == 5 ){ if ( now.getDate() <=21 )
{
mr=now.getDate()+10;
} else { mr=now.getDate()+10-31;
}
}
if ( now.getMonth() == 6 || now.getMonth() == 7 || now.getMonth() == 8 )
{
if ( now.getDate() <=21 ) { mr=now.getDate()+9;
} else { mr=now.getDate()+9-31 ;
}
}
if ( now.getMonth() == 10 || now.getMonth() == 11)
{
if ( now.getDate() <=21 ) { mr=now.getDate()+9 ;
} else { mr=now.getDate()+9-30 ;
}
}
if ( now.getMonth() == 9){ if ( now.getDate() <=22 )
{ mr=now.getDate()+8;
} else { mr=now.getDate()+8-30;
}
}
if ( now.getMonth() == 1 ){ if ( now.getDate() <=20 )
{ mr=now.getDate()+11;
} else { mr=now.getDate()+11-30 ;
}
}
return( rr + "/" + mr + "/" + mm + "/" + ii );

}
}

mojtaba_java
جمعه 16 فروردین 1387, 12:26 عصر
خیلی ممنون از پاسخ دوستان :عصبانی++:

iransohrab
پنج شنبه 19 اردیبهشت 1387, 15:49 عصر
من يه كى بهت مي دم كه خودت بايد باكسش رو تعبيه كني . اين كدم كه آماده شده هم ساعت داره و هم تاريخ :


function showdate() {
week= new Array("يكشنبه","دوشنبه","سه شنبه","چهارشنبه","پنج شنبه","جمعه","شنبه")
months = new Array("فروردين","ارديبهشت","خرداد","تير","مرداد","شهريور","مهر","آبان","آذر","دی","بهمن","اسفند");
a = new Date();
d= a.getDay();
day= a.getDate();
month = a.getMonth()+1;
year= a.getYear();

year = (year== 0)?2000:year;
(year<1000)? (year += 2000):true;

year -= ( (month < 3) || ((month == 3) && (day < 21)) )? 622:621;

switch (month) {
case 1: (day<21)? (month=10, day+=10):(month=11, day-=20); break;
case 2: (day<20)? (month=11, day+=11):(month=12, day-=19); break;
case 3: (day<21)? (month=12, day+=9):(month=1, day-=20); break;
case 4: (day<21)? (month=1, day+=11):(month=2, day-=20); break;
case 5:
case 6: (day<22)? (month-=3, day+=10):(month-=2, day-=21); break;
case 7:
case 8:
case 9: (day<23)? (month-=3, day+=9):(month-=2, day-=22); break;
case 10:(day<23)? (month=7, day+=8):(month=8, day-=22); break;
case 11:
case 12:(day<22)? (month-=3, day+=9):(month-=2, day-=21); break;
default: break;
}
document.write('<b><span style="font-family:Tahoma; font-size: 8pt">' + week[d]+" "+day+" "+months[month-1]+" "+ year + '</span></b>');
}


اميدوارم لذت برده باشي ...


يا علي مدد

mazdadoost
پنج شنبه 19 اردیبهشت 1387, 16:50 عصر
دوست عزیز به روش اصولی که در این پست گفتم :
http://barnamenevis.org/forum/showthread.php?t=104621