格式话的问题~~~~~~(100分)

  • 主题发起人 主题发起人 独孤客
  • 开始时间 开始时间

独孤客

Unregistered / Unconfirmed
GUEST, unregistred user!
Datetime类型如何转换成只有Date的字符串<br>比如说2003-12-1 00:00:00我要把它转换成2003 1-1-1要怎么弄?<br>转换成 12 要怎么弄,<br>还有就是2003-1-1 00:00:00告诉你了有没有什么函数是知道他是今年那个星期的.
 
用format函数
 
?<br>FormatDateTime('yyyy-m-d', now);<br>FormatDateTime('m', now);
 
用FormatDateTime<br>c Displays the date using the format given by the ShortDateFormat global variable, followed by the time using the format given by the LongTimeFormat global variable. The time is not displayed if the date-time value indicates midnight precisely.<br>d Displays the day as a number without a leading zero (1-31).<br>dd Displays the day as a number with a leading zero (01-31).<br>ddd Displays the day as an abbreviation (Sun-Sat) using the strings given by the ShortDayNames global variable.<br>dddd Displays the day as a full name (Sunday-Saturday) using the strings given by the LongDayNames global variable.<br>ddddd Displays the date using the format given by the ShortDateFormat global variable.<br>dddddd Displays the date using the format given by the LongDateFormat global variable.<br>e Displays the year in the current period/era as a number without a leading zero (Japanese, Korean and Taiwanese locales only).<br>ee Displays the year in the current period/era as a number with a leading zero (Japanese, Korean and Taiwanese locales only).<br>g Displays the period/era as an abbreviation (Japanese and Taiwanese locales only).<br>gg Displays the period/era as a full name. (Japanese and Taiwanese locales only).<br>m Displays the month as a number without a leading zero (1-12). If the m specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.<br>mm Displays the month as a number with a leading zero (01-12). If the mm specifier immediately follows an h or hh specifier, the minute rather than the month is displayed.<br>mmm Displays the month as an abbreviation (Jan-Dec) using the strings given by the ShortMonthNames global variable.<br>mmmm Displays the month as a full name (January-December) using the strings given by the LongMonthNames global variable.<br>yy Displays the year as a two-digit number (00-99).<br>yyyy Displays the year as a four-digit number (0000-9999).<br>h Displays the hour without a leading zero (0-23).<br>hh Displays the hour with a leading zero (00-23).<br>n Displays the minute without a leading zero (0-59).<br>nn Displays the minute with a leading zero (00-59).<br>s Displays the second without a leading zero (0-59).<br>ss Displays the second with a leading zero (00-59).<br>z Displays the millisecond without a leading zero (0-999).<br>zzz Displays the millisecond with a leading zero (000-999).<br>t Displays the time using the format given by the ShortTimeFormat global variable.<br>tt Displays the time using the format given by the LongTimeFormat global variable.<br>am/pm Uses the 12-hour clock for the preceding h or hh specifier, and displays 'am' for any hour before noon, and 'pm' for any hour after noon. The am/pm specifier can use lower, upper, or mixed case, and the result is displayed accordingly.<br>a/p Uses the 12-hour clock for the preceding h or hh specifier, and displays 'a' for any hour before noon, and 'p' for any hour after noon. The a/p specifier can use lower, upper, or mixed case, and the result is displayed accordingly.<br>ampm Uses the 12-hour clock for the preceding h or hh specifier, and displays the contents of the TimeAMString global variable for any hour before noon, and the contents of the TimePMString global variable for any hour after noon.<br>/ Displays the date separator character given by the DateSeparator global variable.<br>: Displays the time separator character given by the TimeSeparator global variable.<br>'xx'/"xx" Characters enclosed in single or double quotes are displayed as-is, and do not affect formatting.
 
format函数的具体说明哪有?
 
1.<br>var &nbsp;<br>&nbsp; a:TDateTime;<br>&nbsp; b:string;<br>begin<br>&nbsp; a:=now();//带日期和时间<br>&nbsp; b:=DateToStr(a);<br>&nbsp; self.caption:=b;//只带日期了。<br>end;<br><br>2.用替换字符的方法把:替换成-就可以了。<br>//用formatDateTime格式化日期时间,下面给你个例子,你举一反三<br>FormatDateTime('yyyy"年"m"月"d"日"',Date);<br><br>//DayOfWeek函数可以得到星期几,参看下面代码<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; ADate: TDateTime;<br>&nbsp; days: array[1..7] of string;<br>begin<br>&nbsp; days[1] := 'Sunday';<br>&nbsp; days[2] := 'Monday';<br>&nbsp; days[3] := 'Tuesday';<br>&nbsp; days[4] := 'Wednesday';<br>&nbsp; days[5] := 'Thursday';<br>&nbsp; days[6] := 'Friday';<br>&nbsp; days[7] := 'Saturday';<br>&nbsp; ADate := StrToDate(Edit1.Text);<br>&nbsp; ShowMessage(Edit1.Text + ' is a ' + days[DayOfWeek(ADate)];<br>end;
 
给你个转换时间的源码!自己看去吧!<br>var<br>&nbsp; &nbsp;DateTime,MyDate,MyTime : TDateTime;<br>&nbsp; &nbsp;DateStr,TimeStr:string;<br>begin<br>&nbsp; &nbsp;DateTime := Now; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //返回当前日期时间<br>&nbsp; &nbsp;DateStr:= DateToStr(DateTime); &nbsp; //转换日期为字符串 ,例如:01/08/96<br>&nbsp; &nbsp;TimeStr := TimeToStr(DateTime); &nbsp; //转换时间为字符串,例如:20:50<br>&nbsp; MyDate:= StrToDate(DateStr); //转换字符串为日期<br>&nbsp; MyTime:= StrToTime(TimeStr); //转换字符串为时间<br>&nbsp; DateTime:= MyDate + MyTime; //相加得到datetime<br>&nbsp; DateTime &nbsp; := DateTime + (15/60/24);//加15分钟<br><br>&nbsp; DateStr:= FormatDateTime('yyyy-mmmm-dd',MyDate); &nbsp;{1996-January-08}<br>&nbsp; DateStr:= FormatDateTime('mmm,d,yy,ddd',MyDate); &nbsp;{Jan,8,96,Mon}<br>&nbsp; DateStr:= FormatDateTime('dddd/dd/mm/yy',MyDate); {Monday/08/01/96}<br><br>&nbsp; TimeStr:= FormatDateTime('t',MyTime); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {10:50 PM}<br>&nbsp; TimeStr:= FormatDateTime('tt',MyTime); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{10:50:00 PM}<br>&nbsp; TimeStr:= FormatDateTime('hh-nn-ss-a/p',MyTime); &nbsp;{10-50-00-p}<br>end; <br>////////////////////////////////////////////<br>begin<br>&nbsp;try &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{编码年月日为TDateTime}<br>&nbsp; DateTime := EncodeDate(YearStr, MonthStr,DayStr);<br>&nbsp;except &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; on EConvertError do ....<br>&nbsp;end;<br><br>&nbsp;DOW := DayOfWeek(DateTime); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 获得星期几的信息<br>&nbsp;case DOW of &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;1 : &nbsp;WeekStr:= '星期天'; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;......<br>&nbsp; 7:WeekStr:='星期六'<br>&nbsp;end;<br><br>
 
问题结束~
 
求星期的用<br>&nbsp;dayofweek()<br>截取日期的用<br>decodedata()<br>encodedate()<br>配合使用!<br>
 
后退
顶部