1.JULIAN DATE 定义

2.示例:

定义枚举:

public enum JulianDateType
    {
        /// <summary>
        /// Julian Date (JD)
        /// </summary>
        JD,
        /// <summary>
        /// Julian Day Number (JDN)
        /// </summary>
        JDN,
        /// <summary>
        /// Chronological JD (CJD)
        /// </summary>
        CJD,
        /// <summary>
        /// Reduced JD (RJD)
        /// </summary>
        RJD,
        /// <summary>
        /// Modified JD (MJD)
        /// </summary>
        MJD,
        /// <summary>
        ///  Truncated JD (TJD)
        /// </summary>
        TJD,
        /// <summary>
        /// Dublin JD (DJD)
        /// </summary>
        DJD,
        /// <summary>
        /// Lilian Date
        /// </summary>
        LD,
        /// <summary>
        /// Military Julian Date(yddd)
        /// </summary>
        JDD,
        /// <summary>
        /// Ordinal date
        /// </summary>
        OD
    }

2.转换方法

private static Dictionary<string, int> offsetdictionary = new Dictionary<string, int>()
       {
          {"GMT-12:00",-720},{"GMT-11:00",-660},{"GMT-10:00",-600},{"GMT-09:30",-570},{"GMT-09:00",-540},{"GMT-08:00",-480},
          {"GMT-07:00",-420},{"GMT-06:00",-360},{"GMT-05:00",-300},{"GMT-04:30",-270},{"GMT-04:00",-240},{"GMT-03:30",-210},
          {"GMT-03:00",-180},{"GMT-02:00",-120},{"GMT-01:00",-60},{"GMT-00:00",0},{"GMT+01:00",60},{"GMT+02:00",120},
          {"GMT+03:00",180},{"GMT+03:30",210},{"GMT+04:00",240},{"GMT+04:30",270},{"GMT+05:00",300},{"GMT+05:30",330},
          {"GMT+05:45",345},{"GMT+06:00",360},{"GMT+06:30",390},{"GMT+07:00",420},{"GMT+08:00",480},{"GMT+09:00",540},
          {"GMT+09:30",570},{"GMT+10:00",600},{"GMT+10:30",630},{"GMT+11:00",660},{"GMT+11:30",690},{"GMT+12:00",720},
          {"GMT+12:45",765},{"GMT+13:00",780},{"GMT+14:00",840}
       };

/// <summary>
        /// Calendar to julian date format
        /// </summary>
        /// <param name="_year">year size 4</param>
        /// <param name="_month">month size 2</param>
        /// <param name="_day">day szie 2</param>
        /// <param name="_hours"> hours szie 2</param>
        /// <param name="_minutes">minutes size 2</param>
        /// <param name="_seconds">seconds size 2</param>
        /// <param name="jdtype">enum JulianDateType</param>
        /// <returns>convert julian date value</returns>
        public static string CalendarDateToJD(int _year, int _month, int _day, int _hours, int _minutes, int _seconds, JulianDateType jdtype)
        {
            string calendarstring = "";
            decimal jddate = 0;
            int dayN = 0, feb = 0;
            int cur_offset = offsetdictionary["GMT+08:00"];
            //验证是否为空
            if (((_year % 4) == 0 && (_year % 100) != 0) || (_year % 400) == 0)
            {
                // leap year
                if ((_month == 2) && (_day > 29))
                {
                    //Msg:"Leap year: February cannot have more than 29 days.
                    return "Leap year: February cannot have more than 29 days";
                }
                feb = 29;
            }
            else
            {
                // nonleap year
                if ((_month == 2) && (_day > 28))
                {
                    return "February cannot have more than 28 days.";
                }
                feb = 28;
            }

if (((_month == 4) || (_month == 6) || (_month == 9) || (_month == 11)) && (_day > 30))
            {
                return "This month cannot have more than 30 days.";
            }
            for (var i = 1; i < _month; i++)
            {
                if ((i == 4) || (i == 6) || (i == 9) || (i == 11))
                {
                    dayN += 30;
                }
                else if (i == 2)
                {
                    dayN += feb;
                }
                else
                {
                    dayN += 31;
                }
            }
            double a = 7 * (_year + (_month + 9) / 12) / 4;

double b = 3 * ((_year + (_month - 9) / 7) / 100 + 1) / 4;

double c = 275 * _month / 9;
            jddate = 367 * Convert.ToDecimal(_year) - Convert.ToDecimal(a) - Convert.ToDecimal(b) +

Convert.ToDecimal(c + _day + 1721028.5) + (Convert.ToDecimal(_hours) +

(Convert.ToDecimal(_minutes) / 60) + (Convert.ToDecimal(_seconds) / 3600) - (Convert.ToDecimal(cur_offset) / 60)) / 24;
            switch (jdtype)
            {
                case JulianDateType.JD:
                    calendarstring = Math.Round(jddate, 7).ToString();
                    break;
                case JulianDateType.JDN:
                    calendarstring = jddate.ToString().Substring(0, jddate.ToString().IndexOf("."));
                    break;
                case JulianDateType.CJD:
                    string fraction = "0." + cur_offset;
                    if (fraction.IndexOf("-") > -1) fraction = "0";
                    jddate = Math.Round(jddate, 7) + Convert.ToDecimal(0.5) + Convert.ToDecimal(fraction) * 60 / 100;
                    calendarstring = jddate.ToString();
                    break;
                case JulianDateType.RJD:
                    jddate = jddate - 2400000;
                    calendarstring = Math.Round(jddate, 7).ToString();
                    break;
                case JulianDateType.MJD:
                    jddate = jddate - Convert.ToDecimal(2400000.5);
                    calendarstring = Math.Round(jddate, 7).ToString();
                    break;
                case JulianDateType.TJD:
                    decimal intFraction = _hours * 3600 + _minutes * 60 + _seconds;
                    jddate = jddate - Convert.ToDecimal(2440000.5);
                    calendarstring = jddate.ToString().Substring(0, jddate.ToString().IndexOf(".")) + "/" + intFraction;
                    break;
                case JulianDateType.DJD:
                    calendarstring = Math.Round(jddate - 2415020, 7).ToString();
                    break;
                case JulianDateType.LD:

jddate = jddate - Convert.ToDecimal(2299160.5);
                    calendarstring = jddate.ToString().Substring(0, jddate.ToString().IndexOf("."));
                    break;
                case JulianDateType.JDD:
                    dayN += _day;
                    calendarstring = (_year.ToString() + dayN.ToString()).Substring(3);
                    break;
                case JulianDateType.OD:
                    dayN += _day;
                    calendarstring = _year.ToString() + dayN.ToString();
                    break;
            }

return calendarstring;
        }

Calendar to julian date format的更多相关文章

  1. javascript Date format(js日期格式化) (转)

    方法一:这个很不错,好像是 csdn 的 Meizz 写的: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) ...

  2. [转]javascript Date format(js日期格式化)

    方法一:这个很不错,好像是 csdn 的 Meizz 写的: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q)  ...

  3. javascript Date format(js日期格式化)

    这个用这比较爽,记录一下// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年( ...

  4. [荐]javascript Date format(js日期格式化)

    cnblog:http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html 方法一: // 对Date的扩展,将 Date  ...

  5. JS Date.Format

    // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...

  6. Javascript Date Format

    // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...

  7. Date Format, 时间戳格式化

    // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...

  8. js new Date().Format

    /** * * 对Date的扩展,将 Date 转化为指定格式的String * 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符 * 年(y)可以用 1-4 ...

  9. GG同步sqlserver报错一个案例 Invalid date format

    在里面Oracle表同步sqlserver时间,在sqlserver当应用程序数据的结束.您可能会遇到这个错误. 2014-05-17 17:20:24 WARNING OGG-01154 SQL e ...

随机推荐

  1. Java-Shiro:Shiro

    ylbtech-Java-Shiro:Shiro 1.返回顶部 1. Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码和会话管理.使用Shiro的易于理解的API, ...

  2. Cesium官方教程8-- 几何体和外观效果

    原文地址:https://cesiumjs.org/tutorials/Geometry-and-Appearances/ 几何体和外观效果(Geometry and Appearances) 这篇教 ...

  3. JavaScript性能优化篇js优化

    JavaScript性能优化篇js优化   随着Ajax越来越普遍,Ajax引用的规模越来越大,Javascript代码的性能越来越显得重要,我想这就是一个很典型的例子,上面那段代码因为会被频繁使用, ...

  4. Maven入门指南

    Maven入门指南 本指南旨在第一次为使用Maven的人员提供参考,但也打算作为一本包含公共用例的独立参考和解决方案的工具书.对于新用户,建议您按顺序浏览该材料.对于更熟悉Maven的用户,本指南致力 ...

  5. [SHOI2007] 书柜的尺寸 思维题+Dp+空间优化

    Online Judge:Luogu-P2160 Label:思维题,Dp,空间优化 题面: 题目描述 给\(N\)本书,每本书有高度\(Hi\),厚度\(Ti\).要摆在一个三层的书架上. 书架的宽 ...

  6. hammer.js使用

    手势包括点击(tap),长按(press),滑动(swipe),方向(pan) 使用实例: <!DOCTYPE html> <html> <head> <me ...

  7. BZOJ 1874: [BeiJing2009 WinterCamp]取石子游戏

    Time Limit: 5 Sec Memory Limit: 162 MB Submit: 957 Solved: 394 [Submit][Status][Discuss] Description ...

  8. nodejs + mySQL实践

    1.建立数据库连接:createConnection(Object)方法      该方法接受一个对象作为参数,该对象有四个常用的属性host,user,password,database.与php中 ...

  9. 在线模拟http-post请求

    今天,要测试一个post请求的API,找了下,下面的网站可以直接利用起来,mark下 http://www.atool.org/httptest.php

  10. CentOS 6 忘记root密码的修改方法

    1.Linux的root密码修改不像Windows的密码修改找回,Windows的登录密码忘记需要介入工具进行解决.CentOS6和CentOS7的密码方法也是不一样的,具体如下: 2.centos ...