zoukankan      html  css  js  c++  java
  • 黑马程序员----C#基础知识07

    1、String类型

    (1)由一个或多个字符组成,一般以“”为界;System.String类中定义了很多对字符串的操作:比较、连接、查找子串。
    (2)string.Format实现字符串的格式化;

    例:输入两个整数,输出他们的实数除商,并输出上的第二位小数

    static void Main()

            {

                int i = Convert.ToInt32(Console.ReadLine());

                int j = Convert.ToInt32(Console.ReadLine());

                double shang = (double)i / j;

                string str = string.Format("{0:F3}", shang);------------------------格式化

                char c = str[str.Length - 2];

                Console.WriteLine(c);

    2、日期DateTime类型

    (1)表示时间上的一刻,通常以日期和当天的时间表示。
     例如:
      Console.WriteLine(DateTime.Now);
      DateTime date=new DateTime(2006,2,28,12,12,12);

      Console.WriteLine(date);

      Console.WriteLine(date.DayOfWeek);

      Console.WriteLine(date.DayOfYear);

      TimeSpan duration = new System.TimeSpan(36, 0, 0, 0);

      DateTime jinian = date.Add(duration);

      Console.WriteLine(jinian);

    (2)DateTime的格式化输出

          参数format格式详细用法
       格式字符       关联属性/说明
           d          ShortDatePattern
           D         LongDatePattern
       f     完整日期和时间(长日期和短时间)
         F    FullDateTimePattern(长日期和长时间)
       g     常规(短日期和短时间)
       G     常规(短日期和长时间)
       m、M   MonthDayPattern
       r、R   RFC1123Pattern
       s 使用当地时间的 SortableDateTimePattern(基于 ISO 8601)
       t     ShortTimePattern
       T     LongTimePattern
       u     UniversalSortableDateTimePattern 用于显示通用时间的格式
       U     使用通用时间的完整日期和时间(长日期和长时间)
       y、Y     YearMonthPattern
    (3)使用用DateTime计算特定日期
    DateTime.Now.ToString();//今天
    //7天后
    DateTime.Now.AddDays(7).ToShortDateString();
    //本月范围(本月第一天和最后一天)
    DateTime.Now.ToString("yyyy-MM-01");
    DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).AddMonths(1).AddDays(-1).ToShortDateString();
    //上个月,减去一个月份(得到上个月第一天和最后一天)
    DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).AddMonths(-1).ToShortDateString();                
    DateTime.Parse(DateTime.Now.ToString("yyyy-MM-01")).AddDays(-1).ToShortDateString();

  • 相关阅读:
    Graph neural networks: A review of methods and applications文献阅读
    IMBD数据集处理
    GNN知识整理(二)
    GNN认识整理(一)
    Linux中python中的#!/usr/bin/python
    Linux下运行g++
    itextpdf7自写算法的表格展示 制表符
    itext7 List序号 有序列表 解决中文不显示
    java使用itextpdf7实现导出pdf表格;java使用itextpdf7实现pdf加水印
    csv导出导入工具类 commons-csv导出
  • 原文地址:https://www.cnblogs.com/binxinquan/p/3167640.html
Copyright © 2011-2022 走看看