主頁 > 區塊鏈 > 如何解決列印任何給定年份的所有星期五和星期六的問題?

如何解決列印任何給定年份的所有星期五和星期六的問題?

2022-09-30 00:13:27 區塊鏈

我正在嘗試列印任何給定年份的所有周六和周日。但由于某種原因,該程式不會只列印 2022 年的星期六而不是星期五。我嘗試了不同的年份值,但除了 2022 年之外,仍然沒有找到任何值。我在這里做錯了什么???下面是代碼。

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

public class JavaDayFinder extends Thread {

    int day;
    int year;

    JavaDayFinder(int day, int year) {
        this.day = day;
        this.year = year;
    }

    @Override
    public void run() {
        Calendar calendar = new GregorianCalendar();
        calendar.set(year, Calendar.JANUARY, 1);
        calendar.getTime();
        calendar.set(Calendar.DAY_OF_WEEK, day);
        calendar.getTime();

        while (calendar.get(Calendar.YEAR) == year) {
            System.out.println(calendar.getTime());
            calendar.add(Calendar.DAY_OF_MONTH, 7);
            try {
                Thread.sleep(250);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String[] args) {
        System.out.println("This program prints all the common holidays (Fridays & Saturdays) of any given year.");
        System.out.print("Please input the year of which you want to know the holidays: ");
        Scanner scan = new Scanner(System.in);
        int year = scan.nextInt();
        System.out.println("Given year : "   year);
        System.out.println();

        JavaDayFinder friday = new JavaDayFinder(6, year);
        JavaDayFinder saturday = new JavaDayFinder(7, year);
        friday.start();
        saturday.start();
    }
}

下面是輸出

This program prints all the common holidays (Fridays & Saturdays) of any given year.
Please input the year of which you want to know the holidays: 2022
Given year : 2022

Sat Jan 01 17:05:56 BDT 2022
Sat Jan 08 17:05:56 BDT 2022
Sat Jan 15 17:05:56 BDT 2022
Sat Jan 22 17:05:56 BDT 2022
Sat Jan 29 17:05:56 BDT 2022
Sat Feb 05 17:05:56 BDT 2022
Sat Feb 12 17:05:56 BDT 2022
Sat Feb 19 17:05:56 BDT 2022
Sat Feb 26 17:05:56 BDT 2022
Sat Mar 05 17:05:56 BDT 2022
Sat Mar 12 17:05:56 BDT 2022
Sat Mar 19 17:05:56 BDT 2022
Sat Mar 26 17:05:56 BDT 2022
Sat Apr 02 17:05:56 BDT 2022
Sat Apr 09 17:05:56 BDT 2022
Sat Apr 16 17:05:56 BDT 2022
Sat Apr 23 17:05:56 BDT 2022
Sat Apr 30 17:05:56 BDT 2022
Sat May 07 17:05:56 BDT 2022
Sat May 14 17:05:56 BDT 2022
Sat May 21 17:05:56 BDT 2022
Sat May 28 17:05:56 BDT 2022
Sat Jun 04 17:05:56 BDT 2022
Sat Jun 11 17:05:56 BDT 2022
Sat Jun 18 17:05:56 BDT 2022
Sat Jun 25 17:05:56 BDT 2022
Sat Jul 02 17:05:56 BDT 2022
Sat Jul 09 17:05:56 BDT 2022
Sat Jul 16 17:05:56 BDT 2022
Sat Jul 23 17:05:56 BDT 2022
Sat Jul 30 17:05:56 BDT 2022
Sat Aug 06 17:05:56 BDT 2022
Sat Aug 13 17:05:56 BDT 2022
Sat Aug 20 17:05:56 BDT 2022
Sat Aug 27 17:05:56 BDT 2022
Sat Sep 03 17:05:56 BDT 2022
Sat Sep 10 17:05:56 BDT 2022
Sat Sep 17 17:05:56 BDT 2022
Sat Sep 24 17:05:56 BDT 2022
Sat Oct 01 17:05:56 BDT 2022
Sat Oct 08 17:05:56 BDT 2022
Sat Oct 15 17:05:56 BDT 2022
Sat Oct 22 17:05:56 BDT 2022
Sat Oct 29 17:05:56 BDT 2022
Sat Nov 05 17:05:56 BDT 2022
Sat Nov 12 17:05:56 BDT 2022
Sat Nov 19 17:05:56 BDT 2022
Sat Nov 26 17:05:56 BDT 2022
Sat Dec 03 17:05:56 BDT 2022
Sat Dec 10 17:05:56 BDT 2022
Sat Dec 17 17:05:56 BDT 2022
Sat Dec 24 17:05:56 BDT 2022
Sat Dec 31 17:05:56 BDT 2022

Process finished with exit code 0

uj5u.com熱心網友回復:

好吧,那是因為對于 Friday,代碼行calendar.set(Calendar.DAY_OF_WEEK, day)導致年份設定為 2021,因此while (calendar.get(Calendar.YEAR) == year)由于條件為 false,因此立即跳過該行。

正如 Ole VV 在評論中已經說過的,你不應該再使用Calendar了。使用LocalDateDayOfWeek這是修改后的代碼:

@Override
public void run() {
    var dayOfWeek = DayOfWeek.of(day);
    LocalDate currDate = LocalDate.of(year, 1, 1)
        .with(TemporalAdjusters.nextOrSame(dayOfWeek));

    while (currDate.getYear() == year) {
        System.out.println(currDate);
        currDate = currDate.plusWeeks(1);
        try {
            Thread.sleep(250);
        }
        catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

這是發生的事情:

  • LocalDate.of(year, 1, 1)產生給定年份的 1 月 1 日。
  • TemporalAdjusters.nextOrSame(DayOfWeek)取給定日期并移動到下一個指定的星期幾,如果指定的星期幾,則停留在 1 月 1 日。在 2022 年的示例中,1 月 1 日是星期六,因此產生的日期將是 2022 年 1 月 7 日,因為那是下一個星期五。
  • 在回圈中,currDate.plusWeeks(1)顯然將當前日期增加了一周。(1)

注意:DayOfWeek.MONDAY值為1DayOfWeek.SUNDAY值為7(2)但我同意Ole VV 的觀點:你最好使用DayOfWeek常量而不是整數,因為這樣更易讀。


(1) LocalDate本身是不可變的,因此實際上沒有添加任何內容。相反,會回傳一個新實體并添加一周。

(2)好吧,至少DayOfWeek.of(int dayOfWeek)將這些值映射到相應的星期幾。列舉本身不包含特定值,除了列舉的數值。

uj5u.com熱心網友回復:

tl;博士

使用java.time類、流、lambda 和謂詞的代碼摘錄。

this.datesOfYearforDaysOfWeek(
        Year.of( 2023 ) ,
        Set.of( DayOfWeek.SATURDAY , DayOfWeek.SUNDAY )
)
year.atDay( 1 )
        .datesUntil(
                year
                        .plusYears( 1 )
                        .atDay( 1 )
        )
        .filter(
                date -> dows.contains( date.getDayOfWeek() )
        )
        .toList()

細節

MC Emperor的回答是正確而明智的。為了好玩,我將展示一種不同的方法。雖然我沒有測驗過性能,但可能效率不高。這里我們使用流和 lambda。

我們LocalDate#datesUntil用來獲取LocalDate物件流。請注意,該datesUntil方法使用半開邏輯,其中開頭是包含的,而結尾是排他的。因此,一年從第一年開始,一直到但不包括下一年的第一年。

該類Year代表了一年,使代碼更加清晰和自我記錄。

主要邏輯:

    LocalDate firstOfYear = year.atDay( 1 );
    List < LocalDate > dates =
            firstOfYear
                    .datesUntil( firstOfYear.plusYears( 1 ) )
                    .filter(
                            date -> dows.contains( date.getDayOfWeek() )
                    )
                    .toList();

完整的方法。

List < LocalDate > datesOfYearforDaysOfWeek ( final Year year , final Set < DayOfWeek > dows )
{
    // Validate inputs.
    Objects.requireNonNull( year );
    Objects.requireNonNull( dows );
    if ( dows.isEmpty() ) { throw new IllegalArgumentException( "Days of week is empty." ); }

    // Logic
    LocalDate firstOfYear = year.atDay( 1 );
    List < LocalDate > dates =
            firstOfYear
                    .datesUntil( firstOfYear.plusYears( 1 ) )
                    .filter(
                            date -> dows.contains( date.getDayOfWeek() )
                    )
                    .toList();

    // Result.
    return List.copyOf( dates );  // Effectively a no-op if already an immutable list.
}

用法。

List < LocalDate > dates =
        this.datesOfYearforDaysOfWeek(
                Year.of( 2023 ) ,
                Set.of( DayOfWeek.SATURDAY , DayOfWeek.SUNDAY )
        );

跑的時候。

dates.toString() = [2023-01-01, 2023-01-07, 2023-01-08, 2023-01-14, 2023-01-15, 2023-01-21, 2023-01-22, 2023-01-28, 2023-01-29, 2023-02-04, 2023-02-05, 2023-02-11, 2023-02-12, 2023-02-18, 2023-02-19, 2023-02-25, 2023-02-26, 2023-03-04, 2023-03-05, 2023-03-11, 2023-03-12, 2023-03-18, 2023-03-19, 2023-03-25, 2023-03-26, 2023-04-01, 2023-04-02, 2023-04-08, 2023-04-09, 2023-04-15, 2023-04-16, 2023-04-22, 2023-04-23, 2023-04-29, 2023-04-30, 2023-05-06, 2023-05-07, 2023-05-13, 2023-05-14, 2023-05-20, 2023-05-21, 2023-05-27, 2023-05-28, 2023-06-03, 2023-06-04, 2023-06-10, 2023-06-11, 2023-06-17, 2023-06-18, 2023-06-24, 2023-06-25, 2023-07-01, 2023-07-02, 2023-07-08, 2023-07-09, 2023-07-15, 2023-07-16, 2023-07-22, 2023-07-23, 2023-07-29, 2023-07-30, 2023-08-05, 2023-08-06, 2023-08-12, 2023-08-13, 2023-08-19, 2023-08-20, 2023-08-26, 2023-08-27, 2023-09-02, 2023-09-03, 2023-09-09, 2023-09-10, 2023-09-16, 2023-09-17, 2023-09-23, 2023-09-24, 2023-09-30, 2023-10-01, 2023-10-07, 2023-10-08, 2023-10-14, 2023-10-15, 2023-10-21, 2023-10-22, 2023-10-28, 2023-10-29, 2023-11-04, 2023-11-05, 2023-11-11, 2023-11-12, 2023-11-18, 2023-11-19, 2023-11-25, 2023-11-26, 2023-12-02, 2023-12-03, 2023-12-09, 2023-12-10, 2023-12-16, 2023-12-17, 2023-12-23, 2023-12-24, 2023-12-30, 2023-12-31]

變得更緊湊,但不一定更好。結果相同。

    // Logic
    List < LocalDate > dates =
            year.atDay( 1 )
                    .datesUntil(
                            year
                                    .plusYears( 1 )
                                    .atDay( 1 )
                    )
                    .filter(
                            date -> dows.contains( date.getDayOfWeek() )
                    )
                    .toList();

執行服務

您可能想要使用執行器服務而不是自己管理執行緒。

將您的任務定義為Callable回傳所需日期串列的 a。構造具有所需年份和星期幾的物件。

class DatesForDayOfWeekTask implements Callable < List < LocalDate > >
{
    Year year;
    DayOfWeek dow;

    public DatesForDayOfWeekTask ( final Year year , final DayOfWeek dow )
    {
        this.year = year;
        this.dow = dow;
    }

    @Override
    public List < LocalDate > call ( ) throws Exception
    {
        return datesOfYearforDaysOfWeek( this.year , Set.of( this.dow ) );
    }
}

示例用法。

System.out.println( "INFO - Demo started. "   Instant.now() );

ExecutorService executorService = Executors.newCachedThreadPool();

DatesForDayOfWeekTask saturdayTask = new DatesForDayOfWeekTask( Year.of( 2023 ) , DayOfWeek.SATURDAY );
DatesForDayOfWeekTask sundayTask = new DatesForDayOfWeekTask( Year.of( 2023 ) , DayOfWeek.SUNDAY );

Future < List < LocalDate > > saturdayFuture = executorService.submit( saturdayTask );
Future < List < LocalDate > > sundayFuture = executorService.submit( sundayTask );

System.out.println( "INFO Tasks submitted. Please wait. "   Instant.now() );
try { Thread.sleep( Duration.ofSeconds( 10 ).toMillis() ); } catch ( InterruptedException e ) { throw new RuntimeException( e ); }
this.shutdownAndAwaitTermination( executorService );

try
{
    System.out.println( "saturdayFuture.get() = "   saturdayFuture.get() );
    System.out.println( "sundayFuture.get() = "   sundayFuture.get() );
}
catch ( InterruptedException e ) { throw new RuntimeException( e ); }
catch ( ExecutionException e ) { throw new RuntimeException( e ); }
System.out.println( "INFO - Demo ended. "   Instant.now() );

跑的時候。

INFO - Demo started. 2022-09-28T00:38:58.460930Z
INFO Tasks submitted. Please wait. 2022-09-28T00:38:58.469034Z
saturdayFuture.get() = [2023-01-07, 2023-01-14, 2023-01-21, 2023-01-28, 2023-02-04, 2023-02-11, 2023-02-18, 2023-02-25, 2023-03-04, 2023-03-11, 2023-03-18, 2023-03-25, 2023-04-01, 2023-04-08, 2023-04-15, 2023-04-22, 2023-04-29, 2023-05-06, 2023-05-13, 2023-05-20, 2023-05-27, 2023-06-03, 2023-06-10, 2023-06-17, 2023-06-24, 2023-07-01, 2023-07-08, 2023-07-15, 2023-07-22, 2023-07-29, 2023-08-05, 2023-08-12, 2023-08-19, 2023-08-26, 2023-09-02, 2023-09-09, 2023-09-16, 2023-09-23, 2023-09-30, 2023-10-07, 2023-10-14, 2023-10-21, 2023-10-28, 2023-11-04, 2023-11-11, 2023-11-18, 2023-11-25, 2023-12-02, 2023-12-09, 2023-12-16, 2023-12-23, 2023-12-30]
sundayFuture.get() = [2023-01-01, 2023-01-08, 2023-01-15, 2023-01-22, 2023-01-29, 2023-02-05, 2023-02-12, 2023-02-19, 2023-02-26, 2023-03-05, 2023-03-12, 2023-03-19, 2023-03-26, 2023-04-02, 2023-04-09, 2023-04-16, 2023-04-23, 2023-04-30, 2023-05-07, 2023-05-14, 2023-05-21, 2023-05-28, 2023-06-04, 2023-06-11, 2023-06-18, 2023-06-25, 2023-07-02, 2023-07-09, 2023-07-16, 2023-07-23, 2023-07-30, 2023-08-06, 2023-08-13, 2023-08-20, 2023-08-27, 2023-09-03, 2023-09-10, 2023-09-17, 2023-09-24, 2023-10-01, 2023-10-08, 2023-10-15, 2023-10-22, 2023-10-29, 2023-11-05, 2023-11-12, 2023-11-19, 2023-11-26, 2023-12-03, 2023-12-10, 2023-12-17, 2023-12-24, 2023-12-31]
INFO - Demo ended. 2022-09-28T00:39:08.480522Z

完整的示例代碼。

package work.basil.example.days;

import java.time.*;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.*;

public class App
{
    public static void main ( String[] args )
    {
        App app = new App();
//        app.demo();
        app.demoThreaded();
    }

    private void demo ( )
    {
        List < LocalDate > dates =
                this.datesOfYearforDaysOfWeek(
                        Year.of( 2023 ) ,
                        Set.of( DayOfWeek.SATURDAY , DayOfWeek.SUNDAY )
                );
        System.out.println( "dates.toString() = "   dates );
    }

    List < LocalDate > datesOfYearforDaysOfWeek ( final Year year , final Set < DayOfWeek > dows )
    {
        // Validate inputs.
        Objects.requireNonNull( year );
        Objects.requireNonNull( dows );
        if ( dows.isEmpty() ) { throw new IllegalArgumentException( "Days of week is empty." ); }

        // Logic
        List < LocalDate > dates =
                year.atDay( 1 )
                        .datesUntil(
                                year
                                        .plusYears( 1 )
                                        .atDay( 1 )
                        )
                        .filter(
                                date -> dows.contains( date.getDayOfWeek() )
                        )
                        .toList();

        // Result.
        return List.copyOf( dates );  // Effectively a no-op if already an immutable list.
    }

    private void demoThreaded ( )
    {
        System.out.println( "INFO - Demo started. "   Instant.now() );

        ExecutorService executorService = Executors.newCachedThreadPool();

        DatesForDayOfWeekTask saturdayTask = new DatesForDayOfWeekTask( Year.of( 2023 ) , DayOfWeek.SATURDAY );
        DatesForDayOfWeekTask sundayTask = new DatesForDayOfWeekTask( Year.of( 2023 ) , DayOfWeek.SUNDAY );

        Future < List < LocalDate > > saturdayFuture = executorService.submit( saturdayTask );
        Future < List < LocalDate > > sundayFuture = executorService.submit( sundayTask );

        System.out.println( "INFO Tasks submitted. Please wait. "   Instant.now() );
        try { Thread.sleep( Duration.ofSeconds( 10 ).toMillis() ); } catch ( InterruptedException e ) { throw new RuntimeException( e ); }
        this.shutdownAndAwaitTermination( executorService );

        try
        {
            System.out.println( "saturdayFuture.get() = "   saturdayFuture.get() );
            System.out.println( "sundayFuture.get() = "   sundayFuture.get() );
        }
        catch ( InterruptedException e ) { throw new RuntimeException( e ); }
        catch ( ExecutionException e ) { throw new RuntimeException( e ); }
        System.out.println( "INFO - Demo ended. "   Instant.now() );
    }


    class DatesForDayOfWeekTask implements Callable < List < LocalDate > >
    {
        Year year;
        DayOfWeek dow;

        public DatesForDayOfWeekTask ( final Year year , final DayOfWeek dow )
        {
            this.year = year;
            this.dow = dow;
        }

        @Override
        public List < LocalDate > call ( ) throws Exception
        {
            return datesOfYearforDaysOfWeek( this.year , Set.of( this.dow ) );
        }
    }


    // Boilerplate code taken from `ExecutorService` interface Javadoc, and slightly modified.
    private void shutdownAndAwaitTermination ( ExecutorService executorService )
    {
        executorService.shutdown(); // Disable new tasks from being submitted
        try
        {
            // Wait a while for existing tasks to terminate
            if ( ! executorService.awaitTermination( 60 , TimeUnit.SECONDS ) )
            {
                executorService.shutdownNow(); // Cancel currently executing tasks
                // Wait a while for tasks to respond to being cancelled
                if ( ! executorService.awaitTermination( 60 , TimeUnit.SECONDS ) )
                { System.err.println( "Pool did not terminate" ); }
            }
        }
        catch ( InterruptedException ex )
        {
            // (Re-)Cancel if current thread also interrupted
            executorService.shutdownNow();
            // Preserve interrupt status
            Thread.currentThread().interrupt();
        }
    }
}

uj5u.com熱心網友回復:

解釋:

如果 1 月 1 日是星期六,這意味著該周的星期五將比 1 月 1 日早 1 天,即 12 月 31 日。當您將以下欄位設定為星期五時,它將值設定為 12 月 31 日,并且由于您的 while 條件,它不執行回圈。

calendar.set(Calendar.DAY_OF_WEEK, day);

此代碼不適用于邊緣情況,即從星期六開始的任何一年都不會列印星期五。例如 2011 年、2028 年等。

以下方法設定為每月的第一個星期五/星期六/任何作業日:

    private void setNextAvailableDay(Calendar calendar, int day) {
        Date currTime = calendar.getTime();
        calendar.set(Calendar.DAY_OF_WEEK, day);
        if(currTime.after(calendar.getTime()))
            calendar.add(Calendar.DAY_OF_MONTH, 7);
    }
calendar.set(Calendar.DAY_OF_WEEK, day);
// can be replaced by
setNextAvailableDay(calendar, day)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/510304.html

標籤:爪哇日期

上一篇:是否有任何公式可用于如何在電子表格中顯示從開始日期到結束日期之間的值(月份)

下一篇:按區域設定的IANA日歷使用資料庫

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • JAVA使用 web3j 進行token轉賬

    最近新學習了下區塊鏈這方面的知識,所學不多,給大家分享下。 # 1. 關于web3j web3j是一個高度模塊化,反應性,型別安全的Java和Android庫,用于與智能合約配合并與以太坊網路上的客戶端(節點)集成。 # 2. 準備作業 jdk版本1.8 引入maven <dependency> < ......

    uj5u.com 2020-09-10 03:03:06 more
  • 以太坊智能合約開發框架Truffle

    前言 部署智能合約有多種方式,命令列的瀏覽器的渠道都有,但往往跟我們程式員的風格不太相符,因為我們習慣了在IDE里寫了代碼然后打包運行看效果。 雖然現在IDE中已經存在了Solidity插件,可以撰寫智能合約,但是部署智能合約卻要另走他路,沒辦法進行一個快捷的部署與測驗。 如果團隊管理的區塊節點多、 ......

    uj5u.com 2020-09-10 03:03:12 more
  • 谷歌二次驗證碼成為區塊鏈專用安全碼,你怎么看?

    前言 谷歌身份驗證器,前些年大家都比較陌生,但隨著國內互聯網安全的加強,它越來越多地出現在大家的視野中。 比較廣泛接觸的人群是國際3A游戲愛好者,游戲盜號現象嚴重+國外賬號安全應用廣泛,這類游戲一般都會要求用戶系結名為“兩步驗證”、“雙重驗證”等,平臺一般都推薦用谷歌身份驗證器。 后來區塊鏈業務風靡 ......

    uj5u.com 2020-09-10 03:03:17 more
  • 密碼學DAY1

    目錄 ##1.1 密碼學基本概念 密碼在我們的生活中有著重要的作用,那么密碼究竟來自何方,為何會產生呢? 密碼學是網路安全、資訊安全、區塊鏈等產品的基礎,常見的非對稱加密、對稱加密、散列函式等,都屬于密碼學范疇。 密碼學有數千年的歷史,從最開始的替換法到如今的非對稱加密演算法,經歷了古典密碼學,近代密 ......

    uj5u.com 2020-09-10 03:03:50 more
  • 密碼學DAY1_02

    目錄 ##1.1 ASCII編碼 ASCII(American Standard Code for Information Interchange,美國資訊交換標準代碼)是基于拉丁字母的一套電腦編碼系統,主要用于顯示現代英語和其他西歐語言。它是現今最通用的單位元組編碼系統,并等同于國際標準ISO/IE ......

    uj5u.com 2020-09-10 03:04:50 more
  • 密碼學DAY2

    ##1.1 加密模式 加密模式:https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html ECB ECB : Electronic codebook, 電子密碼本. 需要加密的訊息按照塊密碼的塊大小被分為數個塊,并對每個塊進 ......

    uj5u.com 2020-09-10 03:05:42 more
  • NTP時鐘服務器的特點(京準電子)

    NTP時鐘服務器的特點(京準電子) NTP時鐘服務器的特點(京準電子) 京準電子官V——ahjzsz 首先對時間同步進行了背景介紹,然后討論了不同的時間同步網路技術,最后指出了建立全球或區域時間同步網存在的問題。 一、概 述 在通信領域,“同步”概念是指頻率的同步,即網路各個節點的時鐘頻率和相位同步 ......

    uj5u.com 2020-09-10 03:05:47 more
  • 標準化考場時鐘同步系統推進智能化校園建設

    標準化考場時鐘同步系統推進智能化校園建設 標準化考場時鐘同步系統推進智能化校園建設 安徽京準電子科技官微——ahjzsz 一、背景概述隨著教育事業的快速發展,學校建設如雨后春筍,隨之而來的學校教育、管理、安全方面的問題成了學校管理人員面臨的最大的挑戰,這些問題同時也是學生家長所擔心的。為了讓學生有更 ......

    uj5u.com 2020-09-10 03:05:51 more
  • 位元幣入門

    引言 位元幣基本結構 位元幣基礎知識 1)哈希演算法 2)非對稱加密技術 3)數字簽名 4)MerkleTree 5)哪有位元幣,有的是UTXO 6)位元幣挖礦與共識 7)區塊驗證(共識) 總結 引言 上一篇我們已經知道了什么是區塊鏈,此篇說一下區塊鏈的第一個應用——位元幣。其實先有位元幣,后有的區塊 ......

    uj5u.com 2020-09-10 03:06:15 more
  • 北斗對時服務器(北斗對時設備)電力系統應用

    北斗對時服務器(北斗對時設備)電力系統應用 北斗對時服務器(北斗對時設備)電力系統應用 京準電子科技官微(ahjzsz) 中國北斗衛星導航系統(英文名稱:BeiDou Navigation Satellite System,簡稱BDS),因為是目前世界范圍內唯一可以大面積提供免費定位服務的系統,所以 ......

    uj5u.com 2020-09-10 03:06:20 more
最新发布
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:46:47 more
  • Hyperledger Fabric 使用 CouchDB 和復雜智能合約開發

    在上個實驗中,我們已經實作了簡單智能合約實作及客戶端開發,但該實驗中智能合約只有基礎的增刪改查功能,且其中的資料管理功能與傳統 MySQL 比相差甚遠。本文將在前面實驗的基礎上,將 Hyperledger Fabric 的默認資料庫支持 LevelDB 改為 CouchDB 模式,以實作更復雜的資料... ......

    uj5u.com 2023-04-16 07:28:31 more
  • .NET Core 波場鏈離線簽名、廣播交易(發送 TRX和USDT)筆記

    Get Started NuGet You can run the following command to install the Tron.Wallet.Net in your project. PM> Install-Package Tron.Wallet.Net 配置 public reco ......

    uj5u.com 2023-04-14 08:08:00 more
  • DKP 黑客分析——不正確的代幣對比率計算

    概述: 2023 年 2 月 8 日,針對 DKP 協議的閃電貸攻擊導致該協議的用戶損失了 8 萬美元,因為 execute() 函式取決于 USDT-DKP 對中兩種代幣的余額比率。 智能合約黑客概述: 攻擊者的交易:0x0c850f,0x2d31 攻擊者地址:0xF38 利用合同:0xf34ad ......

    uj5u.com 2023-04-07 07:46:09 more
  • Defi開發簡介

    Defi開發簡介 介紹 Defi是去中心化金融的縮寫, 是一項旨在利用區塊鏈技術和智能合約創建更加開放,可訪問和透明的金融體系的運動. 這與傳統金融形成鮮明對比,傳統金融通常由少數大型銀行和金融機構控制 在Defi的世界里,用戶可以直接從他們的電腦或移動設備上訪問廣泛的金融服務,而不需要像銀行或者信 ......

    uj5u.com 2023-04-05 08:01:34 more
  • solidity簡單的ERC20代幣實作

    // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; import "hardhat/console.sol"; //ERC20 同質化代幣,每個代幣的本質或性質都是相同 //ETH 是原生代幣,它不是ERC20代幣, ......

    uj5u.com 2023-03-21 07:56:29 more
  • solidity 參考型別修飾符memory、calldata與storage 常量修飾符C

    在solidity語言中 參考型別修飾符(參考型別為存盤空間不固定的數值型別) memory、calldata與storage,它們只能修飾參考型別變數,比如字串、陣列、位元組等... memory 適用于方法傳參、返參或在方法體內使用,使用完就會清除掉,釋放記憶體 calldata 僅適用于方法傳參 ......

    uj5u.com 2023-03-08 07:57:54 more
  • solidity注解標簽

    在solidity語言中 注釋符為// 注解符為/* 內容*/ 或者 是 ///內容 注解中含有這幾個標簽給予我們使用 @title 一個應該描述合約/介面的標題 contract, library, interface @author 作者的名字 contract, library, interf ......

    uj5u.com 2023-03-08 07:57:49 more
  • 評價指標:相似度、GAS消耗

    【代碼注釋自動生成方法綜述】 這些評測指標主要來自機器翻譯和文本總結等研究領域,可以評估候選文本(即基于代碼注釋自動方法而生成)和參考文本(即基于手工方式而生成)的相似度. BLEU指標^[^?88^^?^]^:其全稱是bilingual evaluation understudy.該指標是最早用于 ......

    uj5u.com 2023-02-23 07:27:39 more
  • 基于NOSTR協議的“公有制”版本的Twitter,去中心化社交軟體Damus

    最近,一個幽靈,Web3的幽靈,在網路游蕩,它叫Damus,這玩意詮釋了什么叫做病毒式營銷,滑稽的是,一個Web3產品卻在Web2的產品鏈上瘋狂傳銷,各方大佬紛紛為其背書,到底發生了什么?Damus的葫蘆里,賣的是什么藥? 注冊和簡單實用 很少有什么產品在用戶注冊環節會有什么噱頭,但Damus確實出 ......

    uj5u.com 2023-02-05 06:48:39 more