黑马程序员--用户输入一个“2008-01-02”格式的日期,分析用户输入的日期然后按照“2008年1月2日”的格式重新输出。...

------- Windows Phone 7手机开发、.Net培训、期待与您交流! -------

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace test1
 7 {
 8     class Program
 9     {
10         //1、 用户输入一个“2008-01-02”格式的日期,分析用户输入的日期然后按照“2008年1月2日”的格式重新输出。
11         static void Main(string[] args)
12         {
13             //提示用户输入日期的格式。   
14             Console.WriteLine("请输入日期格式:例如:2008-01-02");
15 
16             //接收用户输入的值,赋给字符串变量 date  
17 
18             String date = Console.ReadLine();
19             //分割字符串date分割符为“-”号,为把分割后的值赋给字符串数组dates
20 
21             String[] dates = date.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
22 
23             //处理月份和日期前面带0的字符串
24             int M = 0;
25             int d = 0; ;
26             try
27             {
28                 M = Convert.ToInt32(dates[1]);
29                 d = Convert.ToInt32(dates[2]);
30             }
31             catch (Exception e)
32             {
33                 Console.WriteLine(e.ToString());
34                 return;
35             }
36 
37             //输出新的日期格式为:t1[0]+“年”+ M+“月”+ d+“日”  
38             Console.Write(String.Format("{0}年{1}月{2}日", dates[0], M, d));
39             Console.ReadKey();
40 
41         }
42     }
43 }

 

转载于:https://www.cnblogs.com/yliang/archive/2013/04/30/3051834.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值