第109个母亲节快乐,程序猿特殊的表达

文章目录

  • 前言
  • 🚀 1.母亲节起源
  • 🚀 2.母亲节表达
  • 🌈 1.1 SQL算出母亲节日期
  • 🌈 2.2 python绘图
  • 🌈 2.3.java求指定年份母亲节日期
  • 前言

    今天是星期天,也是母亲节,2022年5月8日,109个母亲节,祝福全天下的妈妈们节日快乐


    🚀 1.母亲节起源

    母亲节(Mother’s Day),是一个感谢母亲的节日。现代的母亲节起源于美国,是每年5月的第二个星期日。母亲们在这一天通常会收到礼物,康乃馨被视为献给母亲的花,而中国的母亲花是萱草花,又叫忘忧草.

    🚀 2.母亲节表达

    🌈 1.1 SQL算出母亲节日期

    🚩 MySQL

    select
    year(curdate()) ‘年份’,
    month(curdate()) ‘月份’,
    weekofyear(curdate()) ‘本年周’,
    dayofyear(curdate()) ‘本年天’,
    DATE_FORMAT(now(), ‘%Y-%m-%d’) ‘日期’,
    TIMESTAMPDIFF(YEAR,‘1913-05-01’, DATE_FORMAT(now(), ‘%Y-%m-%d’)) ‘多少个母亲节’\G

    🚩 Oracle

    select
    to_char(sysdate, ‘yyyy’) 年份,
    to_char(sysdate, ‘MM’) 月份,
    to_char(sysdate,‘iw’) 本年周,
    to_char(sysdate,‘DDD’) 本年天,
    to_char(sysdate, ‘yyyy-mm-dd’) 日期,
    trunc(months_between(sysdate,to_date(‘19130501’,‘yyyymmdd’))/12) 多少个母亲节
    from dual;

    🚩 postgreSQL

    select
    to_char(now(),‘yyyy’) “年份”,
    to_char(now(),‘mm’) “月份”,
    date_part(‘week’, now()) “本年周”,
    extract(doy from now()) “本年天”,
    to_char(now(), ‘yyyy-mm-dd’) 日期,
    extract(‘year’ from now())-extract(‘year’ from to_date(‘1913-05-01’, ‘YYYY-MM-DD’)) 多少个母亲节;

    🌈 2.2 python绘图

    import numpy
    import multidict
    import matplotlib.pyplot as plt
    from scipy.misc import imread
    from wordcloud import WordCloud, ImageColorGenerator
    
    def transform_format(val):
        """
        用于去除杂色
        Arguments:
            val {[array]} -- RGB颜色组
        Returns:
            [array] -- 去除杂色后的值
        """
        if val[0] > 245 and val[1] > 245 and val[2] > 245:
            val[0] = val[1] = val[2] = 255
            return val
        else:
            return val
    
    
    def gen_happy_birthday_cloud(file, name):
        words = multidict.MultiDict()
        # 必须先初始化两个最大权重的
        words.add('母亲节快乐', 10)
        words.add(name, 12)
    
        # 随意插入新的词语
        for i in range(1000):
            words.add('妈妈', numpy.random.randint(1, 5))
            words.add('您辛苦了', numpy.random.randint(1, 5))
            words.add(name, numpy.random.randint(1, 5))
    
        # 设定图片
        bimg = imread(file)
        for color in range(len(bimg)):
            bimg[color] = list(map(transform_format, bimg[color]))
    
        wordcloud = WordCloud(
            background_color='white',
            mask=bimg,
            font_path='simhei.ttf'
        ).generate_from_frequencies(words)
    
        # 生成词云
        bimgColors = ImageColorGenerator(bimg)
    
        # 渲染词云
        plt.axis("off")
        plt.imshow(wordcloud.recolor(color_func=bimgColors))
        plt.savefig(name + '.png')
        plt.show()
    
    gen_happy_birthday_cloud("mother.jpg", "母亲节快乐")
    

    🌈 2.3.java求指定年份母亲节日期

    public class Mother {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            System.out.println("请输入年份:");
            int year = in.nextInt();
            //获取当前时间
            Calendar c = Calendar.getInstance();
            //设置年份
            c.set(Calendar.YEAR, year);
            //设置月份(从0开始,母亲节是五月份第二个星期日,故设置为:4)
            c.set(Calendar.MONTH,4);
            //五月份最大的天数
            int maxDate=c.getActualMaximum(Calendar.DATE);
            int sunDays=0;
            for (int i = 1; i <=maxDate ; i++) {
                c.set(Calendar.DATE,i);
                //判断是周日
                if(c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                    sunDays ++;
                    //第二个周日
                    //退出循环
                    if(sunDays== 2) {
                        break;
                    }
                }
            }
            String date = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
            System.out.printf("%s年的母亲节是:%s",year,date);
        }
    }
    

    作为子女:
    一定要让自己成长的速度快于父母老去的速度,所以永远不要停止学习,加油!
    做最好的自己,树欲静而风不止,子欲养而亲不待!

    来源:IT邦德

    物联沃分享整理
    物联沃-IOTWORD物联网 » 第109个母亲节快乐,程序猿特殊的表达

    发表评论