如何根据用户当地时间回复问候?

时间:2016-09-23 05:50:27

标签: javascript

我想要回声问候,比如Hi(用户名),(留言)!在主页上根据用户当地时间。我知道这个代码是用的。但不知道如何......

imageView.setOnTouchListener(new OnSwipeTouchListener(MyActivity.this) {
    public void onSwipeTop() {
        Toast.makeText(MyActivity.this, "top", Toast.LENGTH_SHORT).show();
    }
    public void onSwipeRight() {
        Toast.makeText(MyActivity.this, "right", Toast.LENGTH_SHORT).show();
    }
    public void onSwipeLeft() {
        Toast.makeText(MyActivity.this, "left", Toast.LENGTH_SHORT).show();
    }
    public void onSwipeBottom() {
        Toast.makeText(MyActivity.this, "bottom", Toast.LENGTH_SHORT).show();
    }

});

1 个答案:

答案 0 :(得分:0)

使用else if条件并提供alert

<script>
var now = new Date();
var hrs = now.getHours(); //getHours takes visitors local time, not server time.
alert(hrs);
var msg = "";

if (hrs >  0) msg = "Mornin' Sunshine!"; // REALLY early
else if (hrs >  6) msg = "Good morning";      // After 6am
else if (hrs > 12) msg = "Good afternoon";    // After 12pm
else if (hrs > 17) msg = "Good evening";      // After 5pm
else msg = "Go to bed!";        // After 10pm

alert(msg);

</script>

如果要在网页中显示使用ID并显示如下

document.getElementById('idname').innerHTML=msg