APEX 日期之间的倒计时器

发布于 2025-01-12 03:33:57 字数 927 浏览 0 评论 0原文

我正在尝试使用下面的代码显示结束日期/时间列和系统日期/时间列之间的倒计时器。它不显示计时器。

我创建了一个页面项 P3_TIMER,它有一个列 P3_STARTDATE。

var timer;

var endDate = new Date();
endDate.setDate(endDate.getDate()); //End date is the sys date

timer = setInterval(function() {
  timeBetweenDates(endDate);
}, 1000);

function timeBetweenDates(toDate) {
  var dateEntered = :P3_STARTDATE;
  var now = new Date();
  var difference = dateEntered.getTime() - now.getTime();

  if (difference <= 0) {

    // Timer done
    clearInterval(timer);
  
  } else {
    
    var seconds = Math.floor(difference / 1000);
    var minutes = Math.floor(seconds / 60);
    var hours = Math.floor(minutes / 60);
    var days = Math.floor(hours / 24);

    hours %= 24;
    minutes %= 60;
    seconds %= 60;

    $("#days").text(days);
    $("#hours").text(hours);
    $("#minutes").text(minutes);
    $("#seconds").text(seconds);
  }
$s('P3_TIMER',timer);
}

I'm trying to display the countdown timer between an enddate/time column and the system date/time column using below code. It's not displaying the timer.

I have created a page item P3_TIMER and it has a column P3_STARTDATE.

var timer;

var endDate = new Date();
endDate.setDate(endDate.getDate()); //End date is the sys date

timer = setInterval(function() {
  timeBetweenDates(endDate);
}, 1000);

function timeBetweenDates(toDate) {
  var dateEntered = :P3_STARTDATE;
  var now = new Date();
  var difference = dateEntered.getTime() - now.getTime();

  if (difference <= 0) {

    // Timer done
    clearInterval(timer);
  
  } else {
    
    var seconds = Math.floor(difference / 1000);
    var minutes = Math.floor(seconds / 60);
    var hours = Math.floor(minutes / 60);
    var days = Math.floor(hours / 24);

    hours %= 24;
    minutes %= 60;
    seconds %= 60;

    $("#days").text(days);
    $("#hours").text(hours);
    $("#minutes").text(minutes);
    $("#seconds").text(seconds);
  }
$s('P3_TIMER',timer);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2025-01-19 03:33:57

无法混合 pl/sql 和 javascript。它们是不同的语言并在不同的环境中运行。

function timeBetweenDates(toDate) {
  var dateEntered = :P3_STARTDATE; >>> This is pl/sql 
  var now = new Date();

P3_STARTDATE 需要转换为 JavaScript 日期对象。这不能直接进行,需要进行一些解析,如下所示

对于下面的示例,假设日期以 DD-MON-YYYY 格式传递。

var timer;

var endDate = new Date();
endDate.setDate(endDate.getDate()); //End date is the sys date

timer = setInterval(function() {
  timeBetweenDates(endDate);
}, 1000);

function parseDate(s) {
  var months = {jan:0,feb:1,mar:2,apr:3,may:4,jun:5,
                jul:6,aug:7,sep:8,oct:9,nov:10,dec:11};
  var p = s.split('-');
  return new Date(p[2], months[p[1].toLowerCase()], p[0]);
}

function timeBetweenDates(toDate) {
  var dateEntered = parseDate(apex.item( "P63_DATE" ).getValue() );
  var now = new Date();
  var difference = dateEntered.getTime() - now.getTime();

  if (difference <= 0) {

    // Timer done
    clearInterval(timer);
  
  } else {
    
    var seconds = Math.floor(difference / 1000);
    var minutes = Math.floor(seconds / 60);
    var hours = Math.floor(minutes / 60);
    var days = Math.floor(hours / 24);

    hours %= 24;
    minutes %= 60;
    seconds %= 60;

    $("#days").text(days);
    $("#hours").text(hours);
    $("#minutes").text(minutes);
    $("#seconds").text(seconds);
  }
apex.item("P63_TIMER").setValue(`Days: ${days}, Hours: ${hours}, Minutes: ${minutes}, Seconds: ${seconds}`);
}

It's not possible to mix pl/sql and javascript. They're different languages and run in different environments.

function timeBetweenDates(toDate) {
  var dateEntered = :P3_STARTDATE; >>> This is pl/sql 
  var now = new Date();

The P3_STARTDATE needs to be converted to a javascript date object. That cannot be directly, some parsing is needed as shown in this thread.

For the example below the assumption is made that the date is passed in format DD-MON-YYYY.

var timer;

var endDate = new Date();
endDate.setDate(endDate.getDate()); //End date is the sys date

timer = setInterval(function() {
  timeBetweenDates(endDate);
}, 1000);

function parseDate(s) {
  var months = {jan:0,feb:1,mar:2,apr:3,may:4,jun:5,
                jul:6,aug:7,sep:8,oct:9,nov:10,dec:11};
  var p = s.split('-');
  return new Date(p[2], months[p[1].toLowerCase()], p[0]);
}

function timeBetweenDates(toDate) {
  var dateEntered = parseDate(apex.item( "P63_DATE" ).getValue() );
  var now = new Date();
  var difference = dateEntered.getTime() - now.getTime();

  if (difference <= 0) {

    // Timer done
    clearInterval(timer);
  
  } else {
    
    var seconds = Math.floor(difference / 1000);
    var minutes = Math.floor(seconds / 60);
    var hours = Math.floor(minutes / 60);
    var days = Math.floor(hours / 24);

    hours %= 24;
    minutes %= 60;
    seconds %= 60;

    $("#days").text(days);
    $("#hours").text(hours);
    $("#minutes").text(minutes);
    $("#seconds").text(seconds);
  }
apex.item("P63_TIMER").setValue(`Days: ${days}, Hours: ${hours}, Minutes: ${minutes}, Seconds: ${seconds}`);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文