Oracle implementation uses a function of time to achieve the output, "Good morning / Good afternoon."

Oracle implementation uses a function of time check out the '' good morning / good afternoon "

Reference article:
the Oracle date Related reference article: http://blog.sina.com.cn/s/blog_6168ee920100l2ye.html

description:

Recently during the report development time, met a demand, troubled for a long time: the user needs a customized welcome page, when users log on in the morning, the page prompts "xxx, good morning!", When the user logs in the afternoon, suggesting that "xxx, afternoon good! ", seemingly simple demand, but not easy to achieve in the report development. Here to sort out various ways to achieve this effect.

Implementation 1: Direct use Oracle date functions to achieve:

Knowledge Point 1 (two built-in date functions):
- morning and afternoon can get 1 way
- return milliseconds of the current UTC time (GMT + 0) timestamp.

select current_timestamp from dual;

Return date formats: from October to August -19 08.52.54.488652 PM +08: 00

- You can get morning and afternoon Mode 2
- return date and time of the session, no arguments, no brackets

select localtimestamp from dual;

Return on schedule format: from October to August -19 08.53.23.875886 PM

Knowledge point 2 (substr interception function):
substr taken:
normal use more, but introduce more:
Usage: select substr (string, starting position, the number of bits taken) from dual;
Note: If you want, then taken back Wang Qianmian , the negative values into the starting position on the line;

So ultimately the statement is as follows:

函数1:
select substr(current_timestamp,-9,2) from dual;

函数2:
select substr(localtimestamp,-2,2) from dual;

Implementation 2: Using html to achieve "good morning / afternoon / evening"

Direct buy previous generation:

js判断早上好,上午好,下午好,傍晚好,晚上好
          <body> 
                     <script language="javaScript"> 
                                    now = new Date(),hour = now.getHours() 
                                    if(hour < 6){document.write("凌晨好!")} 
                                    else if (hour < 9){document.write("早上好!")} 
                                    else if (hour < 12){document.write("上午好!")} 
                                    else if (hour < 14){document.write("中午好!")} 
                                    else if (hour < 17){document.write("下午好!")} 
                                    else if (hour < 19){document.write("傍晚好!")} 
                                    else if (hour < 22){document.write("晚上好!")} 
                                    else {document.write("夜里好!")} 
                      </script> 
         </body> 

Implementation 3: Use js achieve "good morning / afternoon / evening"

Makeup hair: https://blog.csdn.net/weixin_37865166/article/details/89477683

code show as below:

let getTimeState = () => {
    // 获取当前时间
    let timeNow = new Date();
    // 获取当前小时
    let hours = timeNow.getHours();
    // 设置默认文字
    let text = ``;
    // 判断当前时间段
    if (hours >= 0 && hours <= 10) {
        text = `早上好`;
    } else if (hours > 10 && hours <= 14) {
        text = `中午好`;
    } else if (hours > 14 && hours <= 18) {
        text = `下午好`;
    } else if (hours > 18 && hours <= 24) {
        text = `晚上好`;
    }
    console.log(`hours >>>>>`, hours);
    console.log(`text >>>>`, text);
    // 返回当前时间段对应的状态
    return text;
};

You can use when needed

let textState=getTimeState()

to sum up:

In the daily development process, some of the requirements can be achieved in various ways, or choose their own familiar development scenarios for you on the line, for example, report development process, the use of the sql statement to achieve something, it better and better. So this demand, I use the first method.

Published 36 original articles · won praise 46 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_31457413/article/details/99114005