PDA

View Full Version : استفاده از تاریخ شمسی از سرور



BestFriend
شنبه 14 خرداد 1390, 20:22 عصر
با سلام من میخوام تو پروژه از تاریخ شمسی استفاده کنم میخوام هم از سمت سرور تنظیم بشه چون ممکنه تاریخ سیستم کلاینت درست تنظیم نشده باشه باید چی کار کنم؟

با تشکر.

TeacherMath
یک شنبه 15 خرداد 1390, 00:48 صبح
از System.Globalization.PersianCalendar استفاده کن.

BestFriend
یک شنبه 15 خرداد 1390, 08:22 صبح
میخوام اطلاعات تاریخ رو از سرور بگیره نه کلاینت

ali_mnkt
یک شنبه 15 خرداد 1390, 09:56 صبح
با سلام
شمای باید یک store procedure در sql بنویسی و از تابع getdate() اون برای گرفتن تاریخ سرور استفاده کنی

elham1611
جمعه 26 اسفند 1390, 14:40 عصر
لطفا کسی هست که توضیح کملی داشته باشه؟

alonemm
شنبه 27 اسفند 1390, 11:03 صبح
میخوام اطلاعات تاریخ رو از سرور بگیره نه کلاینت

دوست عزیز:
ASP.net یک زبان ServerSide هست و در سمت سرور کامپایل میشه پس تاریخ و زمان هم از سرور گرفته میشه.

برای تاریخ شمسی هم به مثال زیر توجه کنید:


// This example demonstrates the members of the PersianCalendar class.

using System;
using System.Globalization;

class Sample
{
public static void Main()
{
//--------------------------------------------------------------------------------
// Get today's date.
//--------------------------------------------------------------------------------
Console.WriteLine("\n................. Today ...........................\n");
PersianCalendar jc = new PersianCalendar();
DateTime thisDate = DateTime.Now;

// Display the current date using the Gregorian and Persian calendars.
Console.WriteLine("Today is:");
Console.WriteLine(" {0:dddd}, {0} in the Gregorian calendar.", thisDate);
Console.WriteLine(" {0}, {1}/{2}/{3} {4}:{5}:{6} in the Persian calendar.",
jc.GetDayOfWeek(thisDate),
jc.GetMonth(thisDate),
jc.GetDayOfMonth(thisDate),
jc.GetYear(thisDate),
jc.GetHour(thisDate),
jc.GetMinute(thisDate),
jc.GetSecond(thisDate));
//--------------------------------------------------------------------------------
// Fields
//--------------------------------------------------------------------------------
Console.WriteLine("\n............... Fields .............................\n");
Console.WriteLine("PersianEra = {0}", PersianCalendar.PersianEra);
//--------------------------------------------------------------------------------
// Properties
//--------------------------------------------------------------------------------
Console.WriteLine("\n............... Properties .........................\n");
Console.Write("Eras:");
foreach (int era in jc.Eras)
{
Console.WriteLine(" era = {0}", era);
}
//--------------------------------------------------------------------------------
Console.WriteLine("\nGregorian Date Range Supported by the Persian Calendar:");
Console.WriteLine(" From {0:G}", jc.MinSupportedDateTime);
Console.WriteLine(" To {0:G}", jc.MaxSupportedDateTime);
//--------------------------------------------------------------------------------
Console.WriteLine("\nTwoDigitYearMax = {0}", jc.TwoDigitYearMax);
//--------------------------------------------------------------------------------
// Methods
//--------------------------------------------------------------------------------
Console.WriteLine("\n............ Selected Methods .......................\n");

//--------------------------------------------------------------------------------
Console.WriteLine("GetDayOfYear: day = {0}", jc.GetDayOfYear(thisDate));
//--------------------------------------------------------------------------------
Console.WriteLine("GetDaysInMonth: days = {0}",
jc.GetDaysInMonth( thisDate.Year, thisDate.Month,
PersianCalendar.PersianEra));
//--------------------------------------------------------------------------------
Console.WriteLine("GetDaysInYear: days = {0}",
jc.GetDaysInYear(thisDate.Year, PersianCalendar.PersianEra));
//--------------------------------------------------------------------------------
Console.WriteLine("GetLeapMonth: leap month (if any) = {0}",
jc.GetLeapMonth(thisDate.Year, PersianCalendar.PersianEra));
//-------------------------------------------------------------
Console.WriteLine("GetMonthsInYear: months in a year = {0}",
jc.GetMonthsInYear(thisDate.Year, PersianCalendar.PersianEra));
//--------------------------------------------------------------------------------
Console.WriteLine("IsLeapDay: This is a leap day = {0}",
jc.IsLeapDay(thisDate.Year, thisDate.Month, thisDate.Day,
PersianCalendar.PersianEra));
//--------------------------------------------------------------------------------
Console.WriteLine("IsLeapMonth: This is a leap month = {0}",
jc.IsLeapMonth(thisDate.Year, thisDate.Month,
PersianCalendar.PersianEra));
//--------------------------------------------------------------------------------
Console.WriteLine("IsLeapYear: 1370 is a leap year = {0}",
jc.IsLeapYear(1370, PersianCalendar.PersianEra));
//--------------------------------------------------------------------------------

// Get the 4-digit year for a year whose last two digits are 99. The 4-digit year
// depends on the current value of the TwoDigitYearMax property.

Console.WriteLine("ToFourDigitYear:");
Console.WriteLine(" If TwoDigitYearMax = {0}, ToFourDigitYear(99) = {1}",
jc.TwoDigitYearMax, jc.ToFourDigitYear(99));
jc.TwoDigitYearMax = thisDate.Year;
Console.WriteLine(" If TwoDigitYearMax = {0}, ToFourDigitYear(99) = {1}",
jc.TwoDigitYearMax, jc.ToFourDigitYear(99));
}
}
/*
The example produces the following results:

................. Today ...........................

Today is Wednesday, 6/14/2006 11:31:13 AM

............... Fields .............................

PersianEra = 1

............... Properties .........................

Eras: era = 1
MaxSupportedDateTime = 12/31/9999 11:59:59 PM
MinSupportedDateTime = 3/21/0622 12:00:00 AM
TwoDigitYearMax = 1410

................ Methods ...........................

AddMonths: thisDate + 6 months = 12/15/2006 11:31:13 AM
thisDate - 6 months = 12/15/2005 11:31:13 AM
AddYears: thisDate + 5 years = 6/14/2011 11:31:13 AM
thisDate - 3 years = 6/14/2003 11:31:13 AM
GetDayOfMonth: month = 24
GetDayOfWeek: day = Wednesday
GetDayOfYear: day = 86
GetDaysInMonth: days = 31
GetDaysInYear: days = 366
GetEra: era = 1
GetLeapMonth: leap month (if any) = 0
GetMonth: month = 3
GetMonthsInYear: months in a year = 12
GetYear: year = 1385
IsLeapDay: This is a leap day = False
IsLeapMonth: This is a leap month = False
IsLeapYear: 1370 is a leap year = True
ToDateTime:
Gregorian calendar: 6/10/2006 8:30:15 PM
Persian calendar: 3/20/1385 8:30:15 PM
ToFourDigitYear:
If TwoDigitYearMax = 1410, ToFourDigitYear(99) = 1399
If TwoDigitYearMax = 2006, ToFourDigitYear(99) = 1999

*/