首页 > 编程语言 >C# 将数字格式转换为日期格式

C# 将数字格式转换为日期格式

时间:2023-07-12 15:14:00浏览次数:28  
标签:strDateFormat string C# intCount int 日期 格式

        public static string ChgNumToDate(int Numeric, string strDateFormat)
        {
            string NumToDate = "";
            string strNumeric = Convert.ToString(Numeric);
            strDateFormat = strDateFormat.ToUpper();
            int intFmtCount = 0;
            string strTmpChar;
            for (int intCount = 0; intCount <= strDateFormat.Length - 1; intCount++)
            {
                string strFmtChar = strDateFormat.Substring(intCount, 1);
                if (strFmtChar == "Y" || strFmtChar == "M" || strFmtChar == "D")
                {
                    if (intFmtCount <= strNumeric.Length)
                    {
                        strTmpChar = strNumeric.Substring(intFmtCount, 1);
                        intFmtCount = intFmtCount + 1;

                        if (strTmpChar != "")
                        {
                            NumToDate = NumToDate + strTmpChar;
                        }
                    }
                    else
                    {
                        NumToDate = NumToDate + strFmtChar;
                    }
                }
                else
                {
                    NumToDate = NumToDate + strFmtChar;
                }
            }

            return NumToDate;
        }

        public static string ChgNumToTime(int Numeric, string strTimeFormat)
        {
            string NumToDate = "";
            string strNumeric = Convert.ToString(Numeric);
            //do
            //{
            //    strNumeric = "0" + strNumeric;

            //} while (strNumeric.Length < 6);

            while (strNumeric.Length < 6)
            {
                strNumeric = "0" + strNumeric;
            }

            strTimeFormat = strTimeFormat.ToUpper();
            int intFmtCount = 0;
            string strTmpChar;
            for (int intCount = 0; intCount <= strTimeFormat.Length - 1; intCount++)
            {
                string strFmtChar = strTimeFormat.Substring(intCount, 1);
                if (strFmtChar == "H" || strFmtChar == "M" || strFmtChar == "S")
                {
                    if (intFmtCount <= strNumeric.Length)
                    {
                        strTmpChar = strNumeric.Substring(intFmtCount, 1);
                        intFmtCount = intFmtCount + 1;

                        if (strTmpChar != "")
                        {
                            NumToDate = NumToDate + strTmpChar;
                        }
                    }
                    else
                    {
                        NumToDate = NumToDate + strFmtChar;
                    }
                }
                else
                {
                    NumToDate = NumToDate + strFmtChar;
                }
            }

            return NumToDate;
        }

 

标签:strDateFormat,string,C#,intCount,int,日期,格式
From: https://www.cnblogs.com/Mandy-ZQ-Ma/p/17547522.html

相关文章

  • Dockerfile静态扫描
    我们的产物都是基于同一Dockerfile生成,因此我们需要保证这个底层Dockerfile的安全性Dockerfile的写法有很多,我一般会采用最简单的方式,即Dockerfile什么都不处理直接RUN#主要是时区跟源的问题,我们需要重封一次[[email protected]]#catDockerfileFROMalpine:la......
  • 【C++开源库】Windows 下编译 libcurl 库
    Whatislibcurl?libcurl是一个跨平台的网络协议库,支持http,https,ftp,gopher,telnet,dict,file,和ldap协议。libcurl同样支持HTTPS证书授权,HTTPPOST,HTTPPUT,FTP上传,HTTP基本表单上传,代理,cookies和用户认证。想要知道更多关于libcurl的介绍,可以到官网......
  • CentOS 环境下通过 YUM 安装软件
    操作场景为提升用户在云服务器上的软件安装效率,减少下载和安装软件的成本,腾讯云提供了YUM下载源。在CentOS环境下,用户可通过yum命令快速安装软件。对于YUM下载源,用户不需要添加软件源,可以直接安装软件包。操作步骤安装软件使用root帐号登录云服务器,并对应您实......
  • Oracle中rownum与order by的执行顺序 正确的写法应该是:先order by,先包一层查询,再赋ro
    Oracle中rownum与orderby的执行顺序正确的写法应该是:先orderby,先包一层查询,再赋rownum值原文链接:https://blog.csdn.net/u013456370/article/details/122366975selectid,createdate,finvoutypefromnc_ext_fa_ls_pz_hzdocdocwheredoc.company='3000004'andd......
  • C#如何判断为空
    1.使用null合并运算符(??)该运算符用于判断左侧的操作符是否为null,如果为null,则返回右侧的操作数,否则返回左侧的操作数。stringstr=null;stringresult=str??"default";2.使用null条件运算符(?.)该运算符用于判断是否为null,如果不是,则执行后面的成员访问操作;如......
  • Shiro characteristic and attack
    CharacteristicIfRememberMe=deleteMeatCookie,SoItisShiro.ShiroKeyYougetthekeyandtomixavulnerabilitywillgettheserversshellorcontroller.TODO.IfIencounterShiroduringfuturetesting,pleasecomeoverandsupplementthisnote.......
  • TyporaCrack
    typro-1.6.7-Activationpatch(backwardcompatible)Thismethodissuitableforthelatestversion,butitmaytriggerfalsealarmsinantivirussystems.Thespecificstepsareasfollows:1.Downloadthelatestversionfromthetyproofficialwebsite.2.......
  • 华普智通HPCS_60-01 雷达测速车牌识别一体机
    测速牌,测速抓拍一体机,平交路口安全预警,行车安全预警,行人过街安全预警,右转车辆行车安全预警,支路来车安全预警,智能道路安全预警平台,Aiot智能预警雷达测速标志牌,相机抓拍单元,车牌识别设备,是交通安全建设中,重要的组成部分。其中典型的设备应用就有,会车预警系统,弯道预警系统,道路测速抓......
  • vector的相关操作
    插入元素:可以使用insert()函数在指定位置插入一个或多个元素。可以通过指定插入位置的迭代器和插入元素的值或范围来进行插入操作。例如:cppstd::vector<int>v={1,2,3,4,5};v.insert(v.begin()+2,10);//在第三个位置插入元素v.insert(v.begin()+3,3,7);......
  • 10.AbstractQueuedSynchronizer(AQS)
    AbstractQueuedSynchronizer(AQS)AQS入门理论知识概念​ 抽象队列同步器,是用来实现锁或者其它同步器组件的公共基础部分的抽象实现,是重量级基础框架及整个JUC体系的基石,主要用于解决锁分配给"谁"的问题​ 整体就是一个抽象的FIFO队列来完成资源获取线程的排队工作,并通过一个int......