myAdBanner

2013年11月7日 星期四

字串與日期轉換

字串與日期轉換
短日期格式

VB
FormatDateTime(TextBox1.Text, DateFormat.ShortDate)
C#
DateTime strDate = DateTime.Parse(TextBox1.Text)
String.Format(“{0:yyyy/MM/dd}", strDate)

驗證日期




先下載 iTextSharp 目前最新版為itextsharp-all-5.4.0.zip 解壓縮後把 itextsharp.dll 放到bin中 程式中先引用這兩行 using iTextSharp.text; using iTextSharp.text.pdf; 再call這一段函數 TifFN 代表圖片路徑 PdfFN 代表PDF路徑
public void tif2pdf(string TifFN, string PdfFN)
{
    iTextSharp.text.Image image;
    //設定4個邊界
    int Mleft = 0;
    int Mright = 0;
    int Mtop = 0;
    int Mbottom = 0;
 
    Document document = new Document(iTextSharp.text.PageSize.A4, Mleft, Mright, Mtop, Mbottom);
    PdfWriter.GetInstance(document, new FileStream(PdfFN, FileMode.Create));
    document.Open();
 
    image = iTextSharp.text.Image.GetInstance(TifFN);
    //調整圖片大小,使之適合A4
    if (image.Height > iTextSharp.text.PageSize.A4.Height - Mtop)
        image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - Mleft, iTextSharp.text.PageSize.A4.Height - Mtop);
    else if (image.Width > iTextSharp.text.PageSize.A4.Width - Mleft)
        image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - Mleft, iTextSharp.text.PageSize.A4.Height - Mtop);
    //調整圖片位置,使之居中
    image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
    document.NewPage();
    document.Add(image);
    document.Close();
}

判斷日期函數

判斷日期函數
public static bool IsDate(Object obj)
{
    string strDate = obj.ToString();
    try
    {
        DateTime dt = DateTime.Parse(strDate);
        if (dt != DateTime.MinValue && dt != DateTime.MaxValue)
            return true;
        return false;
    }
    catch
    {
        return false;
    }
}

CSS自動分頁列印

CSS自動分頁列印
自動分頁列印!


<SCRIPT LANGUAGE='JavaScript'>

</SCRIPT>

這是列印的第一頁!

這是列印的第二頁!
第二段寫法:
第一頁
第二頁
第三段寫法:
第一頁

第二頁

2013年10月28日 星期一

數字前面補0 使用sprintf

* %% - 返回百分比符號
* %b - 二進位數字
* %c - 依照 ASCII 值的字元
* %d - 帶符號十進位數字
* %e - 可續計數法(比如 1.5e+3)
* %u - 無符號十進位數字
* %f - 浮點數(local settings aware)
* %F - 浮點數(not local settings aware)
* %o - 八進位數
* %s - 字串
* %x - 十六進位數(小寫字母)
* %X - 十六進位數(大寫字母)

< ?php
$number = 123;
$txt = sprintf("With 2 decimals: %1\$.2f
With no decimals: %1\$u",$number);
echo $txt."<br>";
echo sprintf("%05d", 1); 
?>
輸出: With 2 decimals: 123.00 With no decimals: 123 00001